{"id":592,"date":"2018-02-23T23:40:15","date_gmt":"2018-02-23T15:40:15","guid":{"rendered":"http:\/\/60.205.208.74\/2018\/02\/23\/ios-twitter%e5%92%8cfacebook\/"},"modified":"2018-02-23T23:40:15","modified_gmt":"2018-02-23T15:40:15","slug":"ios-twitter%e5%92%8cfacebook","status":"publish","type":"post","link":"https:\/\/www.puzi7.net\/?p=592","title":{"rendered":"iOS Twitter\u548cFacebook"},"content":{"rendered":"<span itemprop=\"description\"><div class=\"article-body\">\n<div class=\"article-intro\" id=\"content\">\n<h1>IOS-Twitter\u548cFacebook<\/h1>\n<hr>\n<h2>\u7b80\u4ecb<\/h2>\n<p>Twitter\u5df2\u7ecf\u6574\u5408\u5230iOS5.0\uff0c\u800cFacebook\u5df2\u7ecf\u88ab\u96c6\u6210\u5728 iOS 6.0\u4e2d\u3002\u672c\u6559\u7a0b\u7684\u91cd\u70b9\u8bb2\u89e3\u5982\u4f55\u5229\u7528\u82f9\u679c\u63d0\u4f9b\u7684\u7c7b\u5728iOS5.0\u548ciOS6.0\u4e2d\u90e8\u7f72Twitter\u548cFacebook\u3002<\/p>\n<h3>\u5b9e\u4f8b\u6b65\u9aa4<\/h3>\n<p>1. \u521b\u5efa\u4e00\u4e2a\u7b80\u5355View based application<\/p>\n<p>2. \u9009\u62e9\u9879\u76ee\u6587\u4ef6\uff0c\u7136\u540e\u9009\u62e9&#8221;targets(\u76ee\u6807)&#8221;\uff0c\u7136\u540e\u5728 choose frameworks\uff08\u9009\u62e9\u6846\u67b6\uff09\u4e2d\u6dfb\u52a0Social.framework \u548c Accounts.framework<\/p>\n<p>3. \u6dfb\u52a0\u4e24\u4e2a\u540d\u4e3afacebookPost \u548c twitterPost\u7684\u6309\u94ae\uff0c\u5e76\u4e3a\u4ed6\u4eec\u521b\u5efa ibActions\u3002<\/p>\n<p>4. \u66f4\u65b0 ViewController.h \u5982\u4e0b<\/p>\n<pre>\n#import &lt;Social\/Social.h&gt;\n#import &lt;Accounts\/Accounts.h&gt;\n#import &lt;UIKit\/UIKit.h&gt;\n\n@interface ViewController : UIViewController\n\n-(IBAction)twitterPost:(id)sender;\n-(IBAction)facebookPost:(id)sender;\n\n@end\n<\/pre>\n<p>5. \u66f4\u65b0ViewController.m \uff0c\u5982\u4e0b\u6240\u793a<\/p>\n<pre>\n#import \"ViewController.h\"\n\n@interface ViewController ()\n\n@end\n\n@implementation ViewController\n\n- (void)viewDidLoad\n{\n    [super viewDidLoad];\n}\n\n- (void)didReceiveMemoryWarning\n{\n    [super didReceiveMemoryWarning];\n    \/\/ Dispose of any resources that can be recreated.\n}\n\n-(IBAction)facebookPost:(id)sender{\n   \n   SLComposeViewController *controller = [SLComposeViewController \n   composeViewControllerForServiceType:SLServiceTypeFacebook];\n   SLComposeViewControllerCompletionHandler myBlock = \n   ^(SLComposeViewControllerResult result){\n          if (result == SLComposeViewControllerResultCancelled)\n          {                \n            NSLog(@\"Cancelled\");                \n          } \n          else                \n          {\n            NSLog(@\"Done\");\n          }\n          [controller dismissViewControllerAnimated:YES completion:nil];\n        };\n   controller.completionHandler =myBlock;        \n   \/\/Adding the Text to the facebook post value from iOS\n   [controller setInitialText:@\"My test post\"];        \n   \/\/Adding the URL to the facebook post value from iOS\n   [controller addURL:[NSURL URLWithString:@\"http:\/\/www.test.com\"]];        \n   \/\/Adding the Text to the facebook post value from iOS\n   [self presentViewController:controller animated:YES completion:nil];    \n}\n\n-(IBAction)twitterPost:(id)sender{\n    SLComposeViewController *tweetSheet = [SLComposeViewController \n    composeViewControllerForServiceType:SLServiceTypeTwitter];\n    [tweetSheet setInitialText:@\"My test tweet\"];\n    [self presentModalViewController:tweetSheet animated:YES];\n}\n\n@end\n<\/pre>\n<h3>\u8f93\u51fa<\/h3>\n<p>\u8fd0\u884c\u8be5\u5e94\u7528\u7a0b\u5e8f\u5e76\u5355\u51fb facebookPost \u65f6\u6211\u4eec\u5c06\u83b7\u5f97\u4ee5\u4e0b\u8f93\u51fa<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"attachment-full\" alt=\"FBTwit_Output1\" src=\"http:\/\/www.runoob.com\/wp-content\/uploads\/2013\/11\/FBTwit_Output1.jpg\" width=\"250\" height=\"491\" data-pinit=\"registered\"><\/p>\n<p>\u5f53\u6211\u4eec\u5355\u51fb twitterPost \u65f6\uff0c\u6211\u4eec\u5c06\u83b7\u5f97\u4ee5\u4e0b\u8f93\u51fa<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"attachment-full\" alt=\"FBTwit_Output2\" src=\"http:\/\/www.runoob.com\/wp-content\/uploads\/2013\/11\/FBTwit_Output2.jpg\" width=\"250\" height=\"494\" data-pinit=\"registered\"><\/p>\n<\/p><\/div>\n<\/p><\/div>\n<span>","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\"><span itemprop=\"description\">IOS-Twitter\u548cFacebook \u7b80\u4ecb Twitter\u5df2\u7ecf\u6574\u5408\u5230iOS5.0\uff0c\u800cF&hellip;<\/span><\/p>\n<p class=\"more-link-p btn-align-right\"><a class=\"green zoom-btn\" href=\"https:\/\/www.puzi7.net\/?p=592\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,26],"tags":[74,93],"class_list":["post-592","post","type-post","status-publish","format-standard","hentry","category-ios","category-mobile","tag-ios","tag-mobile","zoom-theme-has-thumb"],"_links":{"self":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/592","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=592"}],"version-history":[{"count":0,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/592\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}