2016-01-22 59 views
4

在我的應用程序我想創建一個共享按鈕與Whatsup,臉譜,微博,這樣的郵件。 這裏是我的代碼如何在iOS 9中創建分享按鈕?

-(IBAction)share:(id)sender 
{ 
NSString *shareText = @"Hi This is a Reward Game App"; 
NSArray *itemsToShare = @[shareText]; 
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:itemsToShare applicationActivities:nil]; 
activityVC.excludedActivityTypes = @[UIActivityTypePostToWeibo,UIActivityTypePostToTwitter,UIActivityTypePostToFacebook,UIActivityTypeMail,UIActivityTypeMessage,UIActivityTypeAssignToContact,UIActivityTypePostToTencentWeibo]; 
[self presentViewController:activityVC animated:YES completion:nil]; 
} 

我寫這個代碼我的模擬器顯示這個樣子, enter image description here

它只顯示郵件和Facebook的圖標,我想這樣的諾雷的WhatsUp圖標消息。

+0

的可能的複製[如何添加自定義按鈕UIActivityViewController?](http://stackoverflow.com/questions/20029520/how-to-add-custom-buttons-to- uiactivityviewcontroller) –

+1

您無法在模擬器中看到所有應用程序。您必須在設備 – kb920

回答

8

試試這個

-(IBAction)shareAction:(id)sender 

{  
     NSArray* sharedObjects=[NSArray arrayWithObjects:@"sharecontent", nil]; 
     UIActivityViewController *activityViewController = [[UIActivityViewController alloc]                initWithActivityItems:sharedObjects applicationActivities:nil]; 
     activityViewController.popoverPresentationController.sourceView = self.view; 
     [self presentViewController:activityViewController animated:YES completion:nil]; 

    } 
+0

中運行您的應用感謝它的工作! – RealmOfFire