Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Cross-Platform-Entwicklung (https://www.delphipraxis.net/91-cross-platform-entwicklung/)
-   -   iCloud-Drive-Verzeichnis ermitteln (https://www.delphipraxis.net/214593-icloud-drive-verzeichnis-ermitteln.html)

philipp.hofmann 5. Feb 2024 12:03

iCloud-Drive-Verzeichnis ermitteln
 
Hi,

unter iOS legen ich normalerweise in der App selbst das iCloud-Drive-Verzeichnis für die App an.
Damit können auch Apps außerhalb meiner App (z.B. der Browser) auf diese Dateien zugreifen.

Bisher erledigte ich dies mit folgendem Code:

Delphi-Quellcode:
class function TFileUtils.getAppSharedDownloadsPath(appPathRef:String):String;
var nsFile: NSFileManager;
    URL: NSURL;
begin
   nsFile := TNSFileManager.Wrap(TNSFileManager.OCClass.defaultManager);
   URL:=nsFile.URLForUbiquityContainerIdentifier(nil);
   if (URL <> nil) then
   begin
     URL:=URL.URLByAppendingPathComponent(StrToNSStr('Documents'));
     Result := UTF8ToString(URL.path.UTF8String);
     if (not nsFile.fileExistsAtPath(URL.path,nil)) then
     begin
      mlog.info('create new iCloud directory: '+result);
      if (nsFile.createDirectoryAtURL(URL,true,nil,nil)) then
        mlog.info('Created new iCloud directory '+result)
      else
        mlog.info('Can´t creat new iCloud directory '+result);
     end else
      mlog.info('iCloud directory exists: '+result);
   end else begin
     Result := '';
     mlog.info('URLForUbiquityContainerIdentifier is empty');
   end;
end;
Bei einigen Geräten kommt jetzt aber leider als URL nil raus.
Ich habe es auch mit der neusten iOS-Version bei mir erfolgreich (also <>nil) testen können und da kommt dann
Delphi-Quellcode:
        /private/var/mobile/Library/Mobile Documents/iCloud~de~ictrainer/Documents
raus.

Woran kann dieser Fehler also hängen?

Delphi-Quellcode:
   nsFile := TNSFileManager.Wrap(TNSFileManager.OCClass.defaultManager);
   URL:=nsFile.URLForUbiquityContainerIdentifier(nil);


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:41 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz