Reputation: 1925
I am trying to create a share app extension and followed the tutorial from this source:
http://www.technetexperts.com/mobile/share-extension-in-ios-application-overview-with-example/
I am using XCode 8.0 (8A218a) On simulator it works as expected. On my iPhone 5s with iOS 9.3.3.
I install the container application first and then run Extension by choosing Photos app when XCode asks "Choose an app to run".
Now when I open a photo while extension is running, the following error appears:
MobileSlideShow[3500:589624] *** error reading settings archive file: <ISRootSettings:
/var/mobile/Documents/com.apple.mobileslideshow.settings/ISRootSettings_10.plist>
Now when I tap the Share button, my container app doesn't appear in the list of Apps capable of Sharing picture.
EDIT: I am sharing some code:
ShareViewController.m
@implementation ShareViewController
- (BOOL)isContentValid {
// Do validation of contentText and/or NSExtensionContext attachments here
return YES;
}
- (void)didSelectPost {
for (NSItemProvider* itemProvider in ((NSExtensionItem*)self.extensionContext.inputItems[0]).attachments ) {
if([itemProvider hasItemConformingToTypeIdentifier:@"public.jpeg"]) {
NSLog(@"itemprovider = %@", itemProvider);
[itemProvider loadItemForTypeIdentifier:@"public.jpeg" options:nil completionHandler: ^(id<NSSecureCoding> item, NSError *error) {
NSData *imgData;
if([(NSObject*)item isKindOfClass:[NSURL class]]) {
imgData = [NSData dataWithContentsOfURL:(NSURL*)item];
}
if([(NSObject*)item isKindOfClass:[UIImage class]]) {
imgData = UIImagePNGRepresentation((UIImage*)item);
}
NSDictionary *dict = @{
@"imgData" : imgData,
@"name" : self.contentText
};
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.iosApp.testSharing"];
[defaults setObject:dict forKey:@"img"];
[defaults synchronize];
}];
}
}
}
@end
ViewController.m
@implementation ViewController
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.iosApp.testSharing"];
NSDictionary *dict = [defaults valueForKey:@"img"];
if (dict) {
NSData *imgData = [dict valueForKey:@"imgData"];
UIImage *image = [UIImage imageWithData:imgData];
[_shareImageView setImage:image];
_shareImageNameLabel.text = [dict valueForKey:@"name"];
[defaults removeObjectForKey:@"img"];
}
}
@end
Upvotes: 13
Views: 12340
Reputation: 2417
Add / Update the Info.plist of the Share Extension
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsText</key>
<true/>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>1</integer>
</dict>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string> <!-- Or your specific storyboard -->
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
</dict>
Add / Update the Info.plist of of main app (not the Share Extension)
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>public.text</string> <!-- or other types you support -->
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>public.text</string> <!-- depend upon your need -->
<string>public.image</string> <!-- depend upon your need -->
<string>public.audio</string> <!-- depend upon your need -->
</array>
</dict>
</array>
Upvotes: 0
Reputation: 428
For me unchecking the Copy only when installing option worked. This option can be found under Build Phases > Embed App Extensions.
Upvotes: 12
Reputation: 607
Your testing iPhone version is lower than your Deployment Info
setting:
Upvotes: 20
Reputation: 366
You have to make sure what kind extension identifier you need com.apple.ui-services
or com.apple.share-services
that's my configuration example:
This is where it appears using ui-services:
And here using the com.apple.share-services
:
and then:
And for everything works fine, don't forget to make sure that your project has the same deployment info target version that your target (General/Deployment Info/Deployment Target)
see ya, hope it helps!
Upvotes: 6
Reputation: 1003
You have to change the deployment target of share extension form target of your project then it starts working.
Upvotes: 33
Reputation: 1805
I went through the technetexperts tutorial, a probable issue looks like the @"group.iosApp.testSharing"
passed to NSUserDefaults
doesn't matches the one described in .plist
Upvotes: 0