我需要在iOS中實現「share as ...」功能。 例如,一個按鈕命名爲「share as ...」,並彈出一個對話框,其中包含電子郵件,短信,Facebook,Twitter等項目。 我不知道是否有一個標準的對話框做這項工作。實現share功能的標準方式
回答
使用UIActivityViewController後,我相信這是一個比我在下面發佈的更好的解決方案。我留下了我的答案,因爲個人分享方法可能對某人有用。
這是我如何在我的項目實施股的特點:
電子郵件:使用MFMailComposeViewController
。請參閱文件的位置:http://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html
Facebook的Twitter的&:使用SLComposeViewController
。在這裏看到的文檔:http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Reference/SLComposeViewController_Class/Reference/Reference.html
例子:
// prepare and present SLComposeViewController if service is available
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *socialPost = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[socialPost setInitialText:@"TEXT FOR POST"];
[socialPost addImage:[UIImage imageNamed:@"yourImage.png"]];
[self presentViewController:socialPost animated:YES completion:nil];
}
// set up a completion handler
[socialPost setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultDone:
// post was completed
break;
case SLComposeViewControllerResultCancelled:
// post was cancelled
break;
default:
break;
}
}
注意:如果您想發表Twitter的,上面的代碼示例中與SLServiceTypeTwitter
取代SLServiceTypeFacebook
。
搜索後,我發現一種方式在iOS6中通過使用UIActivityViewController似乎相當「標準」的方式。
以下是從developer.apple.com說明:
的UIActivityViewController類是可用來從你的應用程序提供各種服務的標準視圖控制器。該系統提供多種標準服務,例如將項目複製到粘貼板,將內容發佈到社交媒體網站,通過電子郵件或SMS發送項目等等。應用程序還可以定義定製服務。
而且下面是一個對話框,我設法用UIActivityViewController
而繼產生的源代碼我使用:
NSArray *activityItems = [NSArray arrayWithObjects: share_text.text, share_image.image , nil];
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
看着'UIActivityViewController'這是一個比我發佈的更好的共享解決方案。感謝發佈! +1 – rog 2013-03-30 07:01:59
在你ViewController.m:
NSString *message = @"The Flyer http://flyerdream.tumblr.com";
UIImage *image = [UIImage imageNamed:@"flyer"];
NSArray *arrayOfActivityItems = [NSArray arrayWithObjects:message, image, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
initWithActivityItems:arrayOfActivityItems applicationActivities:nil];
[self.navigationController presentViewController:activityVC animated:YES completion:nil];
- 1. 方案標準功能?
- 2. 如何實現Android應用程序的SHARE功能?
- 3. 如何使用SuiteScript實現標準功能
- 4. 實現相同功能的智能方式
- 5. 實現「髒」標記功能的不同方法
- 6. 實現jQuery點擊功能的最佳方式
- 7. 實現自動建議功能的最佳方式?
- 8. 實現忘記密碼功能的最佳方式是什麼?
- 9. 實現繪圖功能的最佳方式,如Keynote
- 10. 正確的方式來實現取消訂閱功能
- 11. 使用innoDb實現搜索功能的最佳方式
- 12. 座標準按鍵功能
- 13. PHP - 修改標準功能
- 14. Android - 現在實現該選項卡的標準方式是什麼?
- 15. Share Intent之後的啓動功能Android
- 16. SystemJS實現什麼標準?
- 17. .NET實現標準Java類
- 18. 有沒有一種檢測方案實現的標準方法?
- 19. 的.bashrc功能實現grepall
- 20. OpenCV的(功能未實現)
- 21. 的功能實現爲lambda
- 22. 實現標籤頁的最佳方式
- 23. 標準的URL編碼功能?
- 24. c + +刪除的標準功能
- 25. 不能使用和作爲參數對象的方法 - 在標準實現上
- 26. 有沒有更多的標準方式從jQuery ajax調用恢復功能?
- 27. 在ESMTP功能中宣傳STARTTLS的標準兼容方式是什麼?
- 28. 是否有將功能代碼轉換爲命令代碼的標準方式?
- 29. 原因四標準庫的實現
- 30. LLVM統一標準類庫的實現
這個討論也符合問題o f如何實際將共享操作*按鈕*放入UI中:http://stackoverflow.com/questions/19736440/how-do-i-create-a-standard-ios-share-button – natevw 2014-05-08 23:22:04