UIActivityViewController not showing body text in gmail

后端 未结 3 1929
半阙折子戏
半阙折子戏 2020-12-21 03:58

I\'m using uiactivityviewcontroller for showing sharing option. Everything working except when user selects the Gmail sharing option. If user chooses email then it shows the

3条回答
  •  抹茶落季
    2020-12-21 04:28

    You can use the URL scheme Gmail to create a subclass of UIActivity:

    The code below was extracted this answer: https://stackoverflow.com/a/12766330/3726577

    //ActivityViewCustomActivity.h
    @interface ActivityViewCustomActivity : UIActivity
    
    @end
    
    //ActivityViewCustomActivity.m
    @implementation ActivityViewCustomActivity
    
    - (NSString *)activityType {
        return @"googlegmail";
    }
    
    - (NSString *)activityTitle {
        return @"Gmail";
    }
    
    - (UIImage *)activityImage {
        // Note: These images need to have a transparent background and I recommend these sizes:
        // iPadShare@2x should be 126 px, iPadShare should be 53 px, iPhoneShare@2x should be 100
        // px, and iPhoneShare should be 50 px. I found these sizes to work for what I was making.
    
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        {
            return [UIImage imageNamed:@"iPadShare.png"];
        }
        else
        {
            return [UIImage imageNamed:@"iPhoneShare.png"];
        }
    }
    
    - (BOOL)canPerformWithActivityItems:(NSArray *)activityItems {
        NSLog(@"%s", __FUNCTION__);
        return YES;
    }
    
    - (void)prepareWithActivityItems:(NSArray *)activityItems {
        NSLog(@"%s",__FUNCTION__);
    }
    
    - (UIViewController *)activityViewController {
        NSLog(@"%s",__FUNCTION__);
        return nil;
    }
    
    - (void)performActivity {
        NSString *email = @"googlegmail:///co?subject=Check it out&body=Check the application";
        email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
    
        [self activityDidFinish:YES];
    }
    

    @implementation ViewController2
    
    - (void)viewDidLoad{
        [super viewDidLoad];
    
        NSString *textItem = @"Check the application";
    
        ActivityViewCustomActivity * ca = [ActivityViewCustomActivity new];
    
        UIActivityViewController *activityVC =
        [[UIActivityViewController alloc] initWithActivityItems:@[textItem] applicationActivities:[NSArray arrayWithObject:ca]];
    
        activityVC.excludedActivityTypes = @[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeSaveToCameraRoll];
        [activityVC setValue:@"Check it out" forKey:@"subject"];
    
        activityVC.completionHandler = ^(NSString *activityType, BOOL completed)
        {
            NSLog(@" activityType: %@", activityType);
            NSLog(@" completed: %i", completed);
        };
    
        [self presentViewController:activityVC animated:YES completion:nil];
    }
    

    See more: http://www.macstories.net/links/gmail-for-ios-url-scheme/

提交回复
热议问题