我需要将文件从一个应用程序发送到另一个应用程序。我使用UIDocumentInteractionController来复制文件。
这是我在 SendingApp 中实现UIDocumentInterationController
的ViewController
代码。
NSString *path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"zip"];
NSURL *urlPath = [NSURL fileURLWithPath:path];
self.docController = [UIDocumentInteractionController interactionControllerWithURL:urlPath];
[docController retain];
docController.delegate = self;
[docController presentOpenInMenuFromRect:self.view.frame
inView:self.view
animated:YES];
docController 是财产。ViewController
实现UIDocumentInteractionControllerDelegate
。
ReceiverApp 设置为处理此扩展名的文件。
我的 ReceiverAppInfo.plist
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>zip</string>
</array>
<key>CFBundleTypeName</key>
<string>ZIP</string>
<key>LSItemContentTypes</key>
<array>
<string>public.zip-archive</string>
<string>com.pkware.zip-archive</string>
</array>
<key>LSHandlerRank</key>
<string>Alternate</string>
</dict>
</array>
在 ReceiverAppDelegate 我使用
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
处理接收文件的打开。
所以问题是这段代码在 iOS 5.1 上完美运行,但在 iOS 6 上不起作用。 UIDocumentInteractionController OpenIn 菜单出现并显示我的 ReceiverApp 但如果您选择应用程序,它不会做任何事情。我查看了控制台,发现 iPhone Simulator 6.1 尝试将文件复制到一个目录,而 Simulator 5.1 复制到另一个目录。
iPhone模拟器 6.1
com.apple.mdt[2342]:
Copy ~/Library/Application Support/iPhone Simulator/6.1/Applications/367D395F-DC8B-4F4C-83C7-B22992E34C64/sendingZIP.app/1.zip ->
/var/mobile/Library/Application Support/Containers/-23.ReceiveApp/Documents/Inbox
iPhone模拟器 5.1
com.apple.mdt[2439]:
Copy ~/Library/Application Support/iPhone Simulator/5.1/Applications/0DE1852A-F803-4583-87BC-8F1EBBE362A4/sendingZIP.app/1.zip ->
~/Library/Application Support/iPhone Simulator/5.1/Applications/927E310A-2766-4709-81CB-0E759F24236D/Documents/Inbox
有人有这样的问题吗?有人知道该怎么做吗?