[iOS] 活動視圖控制器 (UIActivityViewController)

如何分享內容到系統中的分享平台如Facebook/Twitter/Line/Email?

ex:

-(IBAction)shareButtonClicked:(UIButton *)button
 {
 UIImage *exImage = [UIImage imageNamed:@"ex.jpg"];
 UIActivityViewController *avc = [[UIActivityViewController alloc] initWithActivityItems:[NSArray arrayWithObjects:@"Message", exImage, nil] applicationActivities:nil];
 [self presentViewController:avc animated:YES completion:nil];
 }

上面是透過 UIActivityViewController 來分享而不是透過 UIDocumentInteractionController 的 presentOpenInMenuFromRect

 

如何透過 UIActivityViewController 放附件?

try this

NSData *pdfData = [NSData dataWithContentsOfFile:pdfFilePath];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[@"Test", pdfData] applicationActivities:nil];

[self presentViewController:activityViewController animated:YES completion:nil];

and also

NSString *str = [[NSBundle mainBundle] pathForResource:@"AppDistributionGuide" ofType:@"pdf"];   
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[@"Test", [NSURL fileURLWithPath:str]] applicationActivities:nil]; 

 

相關文章:

http://nshipster.com/uiactivityviewcontroller/

Add sharing to your app via UIActivityViewController

相關文章

寫留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *