UIActivityViewController inside a Container View

梦想的初衷 提交于 2020-01-25 04:55:28

问题


I use a UIActivityViewController inside a Container View. I want to share some text by using Email, twitter and facebook. While the last two works perfectly i have a problem with Email. The problem is that the composer view doesn't dismisses either by canceling the event nor by trying to send it! When the ActivityView appears i get the following message:

Launch Services: Registering unknown app identifier com.apple.mobilemail failed 
Launch Services: Unable to find app identifier com.apple.mobilemail

This is strange since there is really no problem with the app identifier and i can share text with email, using ActivityViewController in other view controllers (when not in a container view). My code, below:

- (void)openBtnTouched {
    NSString *alertTitleString = [[[GlobalVariables sharedInstance].alertsArray objectAtIndex:self.selectedIndex]objectForKey:@"alertTitle"];
    NSString *alertMsgString = [[[GlobalVariables sharedInstance].alertsArray objectAtIndex:self.selectedIndex]objectForKey:@"alertMessage"];

    UIActivityViewController *activity;

    activity = [[UIActivityViewController alloc] initWithActivityItems:@[alertTitleString,alertMsgString] applicationActivities:nil];

    activity.excludedActivityTypes = @[
                                       UIActivityTypeMessage,
                                       UIActivityTypePostToWeibo,
                                       UIActivityTypeSaveToCameraRoll,
                                       UIActivityTypeAssignToContact,UIActivityTypeCopyToPasteboard];

    activity.completionHandler = ^(NSString *activityType, BOOL completed){
        NSLog(@"Activity Type selected: %@", activityType);
        if (completed) {
            NSLog(@"Selected activity was performed.");
        } else {
            if (activityType == NULL) {
                NSLog(@"User dismissed the view controller without making a selection.");
            } else {
                NSLog(@"Activity was not performed.");
            }
        }
    };
    [self presentViewController:activity animated:YES completion:NULL];
}

回答1:


I'm not sure whether your app is designed for iPhone, iPad, or both, but Apple are very specific about how to display a UIActivityViewController. From their documentation:

When presenting the view controller, you must do so using the appropriate means for the current device. On iPad, you must present the view controller in a popover. On iPhone and iPod touch, you must present it modally.

If you're displaying it in some other way (i.e, in a container view controller) you may well encounter this sort of weird behavior. I'd recommend you display the activity view controller as recommended by Apple.



来源:https://stackoverflow.com/questions/16895024/uiactivityviewcontroller-inside-a-container-view

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!