我希望能够使用默认的“分享到其他服务”菜单,以便可以分享到Twitter、Facebook、电子邮件等平台。
我不知道如何从我的应用程序中显示此视图——我该怎么做?
我希望能够使用默认的“分享到其他服务”菜单,以便可以分享到Twitter、Facebook、电子邮件等平台。
我不知道如何从我的应用程序中显示此视图——我该怎么做?
您可以使用简单的活动控制器来展示默认的分享应用,如下:
NSArray *activityItems = [NSArray arrayWithObjects:shareString, shareImage, shareUrl, nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:activityViewController animated:YES completion:nil];
你也可以使用它的完成处理程序:
[activityViewController setCompletionHandler:^(NSString *act, BOOL done)
{
//Code here when the action performed.
}];
这将显示所有默认共享应用程序。
UIBarButtonItem
触发。// "Share" action
- (IBAction)share:(UIBarButtonItem *)sender {
NSString* title = "Content Title";
NSString* link = "http://example.com/content.url";
NSArray* dataToShare = @[title, link];
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
// This is key for iOS 8+
activityViewController.popoverPresentationController.barButtonItem = sender;
[self presentViewController:activityViewController
animated:YES
completion:^{}];
}
这里是一个段落。
let activityViewController = UIActivityViewController(activityItems: ["Share Me!"], applicationActivities: nil)
activityViewController.completionWithItemsHandler = { [weak self] activityType, completed, returnedItems, activityError in
// Note: you won't need returnedItems in most cases
// It is included in this example for completion's sake
}
present(activityViewController, animated: true, completion: nil)
这里提供了有关完成处理程序的完整文档: https://developer.apple.com/documentation/uikit/uiactivityviewcontrollercompletionwithitemshandler
UIActivityViewController
。 - rmaddy