Home > Software design >  UIActivityViewController not showing Message option When Sharing Image Object
UIActivityViewController not showing Message option When Sharing Image Object

Time:09-16

I am using UIActivityViewController to share my generated image, it worked fine for certain apps like Whatsapp or sharing via Email, but i also wanted to share it using Messages app. I've tried several ways to do it but i can't display Messages app on it. Here's my code :

UIImage *receiptStage3 = [CreateReceiptImage putLogo:nil putLabel:TRANSACTION_RECEIPT inImage:receiptStage2];

NSData *imageData = UIImageJPEGRepresentation(receiptStage3,0.5);

// create url
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
NSString *fileName = [NSString stringWithFormat:@"%@%@%@", @"FormatHere-", [dateFormatter stringFromDate:[NSDate date]],@".jpg"];
NSURL *url = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingString:fileName]];
NSData *data = imageData;
// write data
[data writeToURL:url atomically:NO];
NSArray *activityItems = @[url];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes = @[UIActivityTypePostToTencentWeibo, UIActivityTypePostToVimeo, UIActivityTypePostToWeibo, UIActivityTypePostToFlickr, UIActivityTypePostToTwitter, UIActivityTypePostToFacebook, UIActivityTypePrint, UIActivityTypeAssignToContact, UIActivityTypeOpenInIBooks, UIActivityTypeAirDrop,UIActivityTypeSaveToCameraRoll,UIActivityTypeAddToReadingList];
[activityVC setCompletionWithItemsHandler:^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
    //Delete file
    NSError *errorBlock;
    if([[NSFileManager defaultManager] removeItemAtURL:url error:&errorBlock] == NO) {
        NSLog(@"error deleting file %@",@"error");
        return;
    }
}];
                        
[self presentViewController:activityVC animated:YES completion:nil];

As i said before i've tried several ways like putting NSUrl @[url] and UIImage *receiptStage3 directly to initWithActivityItems. I've also tried to remove excludedActivityTypes but the Message option wont show. Am i missing something ? or are there another ways to do this ? Thanks before

CodePudding user response:

Your code is completely fine, works to me.

First of all you Messages app may be missing if you have iMessage disabled in your settings. Go to Settings->Messages and make sure it's on:

Also you may not see it in the default items, check out hidden ones:

  • Related