Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 356
Saurabh Bhatia Avatar asked Feb 16 '17 09:02

Saurabh Bhatia


4 Answers

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

like image 86
Deepak Saki Avatar answered Nov 18 '22 16:11

Deepak Saki


Your testing iPhone version is lower than your Deployment Info setting:

e

like image 37
yuanjilee Avatar answered Nov 18 '22 14:11

yuanjilee


For me unchecking the Copy only when installing option worked. This option can be found under Build Phases > Embed App Extensions.

like image 6
krishan kumar Avatar answered Nov 18 '22 15:11

krishan kumar


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:

ui services

This is where it appears using ui-services:

enter image description here

And here using the com.apple.share-services :

enter image description here

and then:

enter image description here

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!

like image 4
Igor Romcy Avatar answered Nov 18 '22 16:11

Igor Romcy