Android0077
Android0077

Reputation: 401

iOS - Move item between applications, via share extension

There are 2 applications:

  1. WhatsApp application
  2. My application(testAPP)

I try to share a audio file between WhatsApp to my app (testAPP),I already implement APP Group and share extension.

I succeed to integrate between those application and receive a url, like this:

file:///private/var/mobile/Containers/Data/Application/xxxxxx/tmp/documents/xxxxxx/2017-04-16-AUDIO-00001077.opus

The problem start when I try to move this file to my local document application, for example

Destination path: startingPath = /private/var/mobile/Containers/Data/Application/xxxxxx/tmp/documents/xxxxxx/2017-04-16-AUDIO-00001077.opus

Target path: endingPath = /var/mobile/Containers/Data/Application/685A0D6F-AB7C-4DCF-ADD9-19AAE6A8DAFD/Documents

    do {
        try filemgr.moveItem(atPath: startingPath, toPath: endingPath!)
    } catch let error as NSError {
        NSLog("Unable to create directory \(error.debugDescription)")
    }

I get this error and I dont understand why

Unable to create directory Error Domain=NSCocoaErrorDomain Code=516 "“2017-04-16-AUDIO-00001077.opus” couldn’t be moved to “xxxx” because an item with the same name already exists." UserInfo={NSSourceFilePathErrorKey=/private/var/mobile/Containers/Data/Application/xxxxx/tmp/documents/xxxxxxx/2017-04-16-AUDIO-00001077.opus, NSUserStringVariant=( Move ), NSDestinationFilePath=/var/mobile/Containers/Data/Application/6xxxx/Documents, NSFilePath=/private/var/mobile/Containers/Data/Application/xxxxx/tmp/documents/xxxxxx2/2017-04-16-AUDIO-00001077.opus, NSUnderlyingError=0x17005f6b0 {Error Domain=NSPOSIXErrorDomain Code=17 "File exists"}}

Upvotes: 0

Views: 2224

Answers (1)

Android0077
Android0077

Reputation: 401

Finally I understand the problem.

When application use share extension in order to share file/image... inside to your application, the file exist in this location:

/private/var/mobile/Containers/Data/Application/

in order to get full permission to file, need to copy the file to app group shared folder:

/private/var/mobile/Containers/Shared/AppGroup/

after you move the file to app group shared folder you will get a full permission to the file

Upvotes: 0

Related Questions