0

I want to create a share extension for my app just like whatsapp and skype has. Basically, I want to save a photo from photo library to my app with share extension. I found that I can use UIDocumentInteractionController but I couldn't find any detailed documentation on it which I can consider and make a share extension with my custom UI to save photo.

Below is my code to save the selected photo to my app.

    - (IBAction)acceptButtonTapped:(id)sender
{
    __block UIImage *photo;
    for (NSExtensionItem *item in self.extensionContext.inputItems)
    {
        for (NSItemProvider *itemProvider in item.attachments)
        {
            if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeImage])
            {
                [itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeImage options:nil completionHandler:^(UIImage *image, NSError *error) {
                    if(image)
                    {
                        dispatch_async(dispatch_get_main_queue(), ^{
                            photo = image;

                            NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

                            [formatter setDateFormat:@"yyyy_MM_dd_hh_mm_ss"];

                            NSString *fileName;

                            fileName = [NSString stringWithFormat:@"%@.jpeg",[formatter stringFromDate:[NSDate date]]];

                            dataPath = [dataPath stringByAppendingPathComponent:fileName];
                            NSData * imageData = [NSData dataWithData:UIImageJPEGRepresentation(image, 1.0)];
                            BOOL isdone = [imageData writeToFile:dataPath atomically:NO];
                            NSLog(@"%u", isdone);
                        });
                    }
                }];
                break;
            }
        }
    }

    [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
}

Any help would be much appreciable.

Thanks you.

Paras Gorasiya
  • 1,295
  • 2
  • 13
  • 33
  • 1
    Could you provide any code as to what you have tried? People are here to help not to work for free :) – C_B Mar 29 '16 at 09:40
  • I have added a target for share extension and its showing my app when i go to photo library and press share button, but upon pressing my app icon it shows a popup with that selected image and a text area which I dont want. I want to present a view controller of my app and save that photo. – Paras Gorasiya Mar 29 '16 at 11:16
  • Please help me if you know about how to implement this feature in Xamarin Ios. – Kushal Vora Jul 05 '16 at 08:53

0 Answers0