I do not have permission to write into iCloud folder

2.6k Views Asked by At

I'm trying to write a file into ubiquitous folder, I can run a query and all works fine, I see the files, but If I try to set a local file I obtain this error:

Error Domain=NSCocoaErrorDomain Code=513 "“video.mp4” couldn’t be moved because you don’t have permission to access “DemoExample”." UserInfo={NSSourceFilePathErrorKey=/var/containers/Bundle/Application/3C3DC6B5-7B22-4B1C-B8AB-187F640F68AB/DemoExample.app/video.mp4, NSUserStringVariant=(
Move
), NSDestinationFilePath=/private/var/mobile/Library/Mobile Documents/iCloud~com~Test~DemoExample/Documents/video.mp4, NSFilePath=/var/containers/Bundle/Application/3C3DC6B5-7B22-4B1C-B8AB-187F640F68AB/DemoExample.app/video.mp4, NSUnderlyingError=0x17405c5c0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

Video.mp4 exists in folder, what wrong?

here is the code for save file:

try self.fileManager.setUbiquitous(true, itemAt: URL.init(fileURLWithPath:file.path), destinationURL: iCloudUrl)

I use this:

<key>NSUbiquitousContainers</key>
<dict>
    <key>iCloud.com.Test.DemoExample</key>
    <dict>
        <key>NSUbiquitousContainerIsDocumentScopePublic</key>
        <true/>
    <key>NSUbiquitousContainerName</key>
    <string>backup</string>
    <key>NSUbiquitousContainerSupportedFolderLevels</key>
    <string>Any</string>
</dict>

2

There are 2 best solutions below

0
On

Please follow the below steps one by one. Hope it will solve your problem....

  1. Enable iCloud from Capabilities under XCode settings area.

enter image description here

  1. Update your AppID and provisioning profile by enabling iCloud.

enter image description here

  1. Add below property in your info.plist.
<key>NSUbiquitousContainers</key>
<dict>
    <key>iCloud.YOUR_BUNDLE_IDENTIFIER</key>
    <dict>
        <key>NSUbiquitousContainerIsDocumentScopePublic</key>
        <true/>
        <key>NSUbiquitousContainerSupportedFolderLevels</key>
        <string>Any</string>
        <key>NSUbiquitousContainerName</key>
        <string>iCloudDriveDemo</string>
    </dict>
</dict>
  1. iCloud.YOUR_BUNDLE_IDENTIFIER is very important here. For example your bundle identifier is “com.emraz.myapp”. Then you have to use “iCloud.com.emraz.myapp”
0
On

Here is my solution (@emraz didn't work for me):

  1. Uninstall the app on all devices
  2. Delete the folder in the Files.app (iOS) if visible.
  3. Delete every folder related to the application from ~/Library/Application Support/CloudDocs/session/containers
  4. Delete every folder related to the application from ~/Library/Mobile\ Documents/
  5. Reboot after a few minutes
  6. Remove the Scheme you are using in XCode
  7. Add back a new Scheme (same name is ok)