Search code examples
iosobjective-ciphonexcode

Share Extension not appearing in the list of apps on capable of Sharing Photo on iPhone


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

Solution

  • You have to change the deployment target of share extension form target of your project then it starts working.