質問

I tried to use - (NSURL *)containerURLForSecurityApplicationGroupIdentifier:(NSString *)groupIdentifier to save / load files between container app and extension on iOS 8 b4.

Here's the code:

NSURL *containerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:groupID];
containerURL = [containerURL URLByAppendingPathComponent:[NSString stringWithFormat:@"Library/Caches/test.txt"]];
NSString* string = @"hihihihihi";
NSError* error;
[string writeToURL:containerURL atomically:YES encoding:NSUTF8StringEncoding error:&error];
NSLog(@"%@",error);

I put this code in both the extension (custom keyboard) and container app. When I run it on iOS Simulator, both of them can save the file successfully. However on iOS Devices, the extension can't save the file (while container app still can)

The console shows cocoa error 513 when the extension tried to save file.

2014-07-31 01:37:49.316 TestExtention[2359:288820] Error Domain=NSCocoaErrorDomain Code=513 "The operation couldn’t be completed. (Cocoa error 513.)" UserInfo=0x15df2100 {NSFilePath=/private/var/mobile/Containers/Shared/AppGroup/4FA2DA5E-89C3-4BC3-AA5B-DD869827C5E7/Library/Caches/test.txt, NSUnderlyingError=0x15df1d90 "The operation couldn’t be completed. Operation not permitted"}

Is this a limitation of iOS 8 extension?

役に立ちましたか?

解決

There's another restriction for keyboard extension. You should set RequestsOpenAccess to YES in Info.plist then it can access the files.

https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html#//apple_ref/doc/uid/TP40014214-CH16-SW2

他のヒント

Both the containing app and the extension can access files under the same shared group container, if they have same group id.

In both of your containing app and extension, check whether this exists in it's .entitlements.

<key>com.apple.security.application-groups</key>
<array>
    <string>your-group-id</string>
</array>


Then check their Provisioning Profile has this group id.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top