ios6.0 调用系统api 分享到 twitter facebook weibo
2013-04-23 13:56
471 查看
Overview: Social Features
There are three ways you can share to social media sites:The
UIActivityViewControllerclass allows your app to provide several services in context, one of which would be posting content to social media sites.
The
SLComposeViewControllerclass is targeted more to social media sites, allowing users of your app to compose a post to send to those sites.
The
SLRequestis the third way that you can integrate with social media sites. This provides you a way to wrapHTTP requests to these sites to perform servers, such as sharing content directly via an API provided by that site. For example, posting to Facebook requires you to send an HTTP POST to the http://graph.facebook.com/[FacebookUserId]/feed endpoint with the data you wish to post. Using this class requires more work than the previous two but provides more functionality.
I’ll walk through how you can use each of these classes to post content to Facebook and Twitter. Here are the topic areas I’ll cover:
Sharing via the Share Sheet
Sharing via the Composer
Sharing via the Social Media Site APIs (Facebook)
Sharing via the Social Media Site APIs (Twitter)
Sharing via the Share Sheet
Using theUIActivityViewControlleris the easiest way to implement sharing. It’s scope is broad and gives uses the option to share content based on the type of content. For example, if you pass in info that you’re sharing text, users will see options to share via e-mail, SMS, Twitter, Facebook, etc. The advantage again, is the ease of implementation.
Step 1: Add a button to your view that will launch the share sheet.
Go to your .xib file and add a Round Rect Button to your view.Add an action for this button to your view controller implementation file.
Step 2: Add the logic behind the button.
Let’s find an image that you’ll use for sharing. Find your favorite image (PNG format), download it and drag it into your project.Find the action method that was pre-populated in the previous step.
Add the following code:
NSString *message = @"Hello World!"; UIImage *imageToShare = [UIImage imageNamed:@"test.jpg"]; NSArray *postItems = @[message, imageToShare]; UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:postItems applicationActivities:nil]; [self presentViewController:activityVC animated:YES completion:nil];
Step 3: Build and Test
Build and run the project on an iOS6 simulator. If this is the first time using your simulator log in to your Facebook and Twitter accounts to test out sharing to those social networks. You can log in by going to the device’s Setting app and entering your login info for Twitter and Facebook. Head back to the app and re-launch it. Click on the button. You should see something similar to this when you click the button then select Facebook and next Twitter:![](http://cocoacontrols-blog.s3.amazonaws.com/ios6_facebook/ios6tut_share_sheet_1.jpg)
![](http://cocoacontrols-blog.s3.amazonaws.com/ios6_facebook/ios6tut_share_sheet_facebook.jpg)
![](http://cocoacontrols-blog.s3.amazonaws.com/ios6_facebook/ios6tut_share_twitter.jpg)
This is the simplest form of sharing. Now let’s move on to the next one, using the
SLComposeViewControllerclass to narrow the share site choices to only social networks.
Build and Test
Build and run the project on an iOS6 simulator. Click on the Facebook composer button. You should see something similar to this:![](http://cocoacontrols-blog.s3.amazonaws.com/ios6_facebook/ios6tut_composer_facebook.jpg)
![](http://cocoacontrols-blog.s3.amazonaws.com/ios6_facebook/ios6tut_composer_story_facebook.jpg)
Click on the Twitter composer button. You should see something similar to this:
![](http://cocoacontrols-blog.s3.amazonaws.com/ios6_facebook/ios6tut_composer_twitter.jpg)
![](http://cocoacontrols-blog.s3.amazonaws.com/ios6_facebook/ios6tut_composer_story_twitter.jpg)
出处:https://www.cocoacontrols.com/posts/2012/10/15/social-media-site-sharing-with-the-ios6-sdk
相关文章推荐
- iOS 系统自带分享包括(新浪微博 腾讯微博 Twitter Facebook LinkedIn)
- ios 调用系统自带分享
- iOS 调用系统原生分享的一些体会
- iOS实现向多个社交网站(facebook,微信,微博,twitter等)分享的代码,支持iPhone和iPAD(分享链接编码)
- ios学习:swift中实现分享到微博、facebook,twitter等
- iOS-调用系统的短信和发送邮件功能,实现短信分享邮件分享
- ios6.0系统自带分享到新浪微博
- iOS社交分享Twitter、Facebook、复制到剪切板、LINE、及邮件
- IOS进阶之Social.framework一键分享文字图片到新浪微博,facebook,twitter 还有保存打印等
- 小胖说事8------iOS 调用系统的短信和发送邮件功能,实现短信分享邮件分享
- iOS调用系统视频分享参考
- 社交网络编程API之iOS系统自带分享
- IOS 调用系统发邮件Api
- iOS开发之调用系统原生分享功能
- 利用UIActivityController调用ios系统自带的分享功能,实现微信发布多图的功能
- Android app中调用启动其他应用(系统应用和第三方应用)2016.10.25新增android 6.0打电话api
- iOS中facebook与twitter分享问题总结
- IOS-系统API调用联系人信息
- iOS中 读取相册,调用系统相机 技术分享