标签:string port copyto frame 关注 intro create nsstring 程序
原文链接:http://blog.csdn.net/daleiwang/article/details/34081231
(1)官方下载ShareSDK iOS 2.8.8,地址:http://sharesdk.cn/
![技术分享](http://img.blog.csdn.net/20140624102618484?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGFsZWl3YW5n/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
(2)根据实际情况,引入相关的库,参考官方文档。
![技术分享](http://img.blog.csdn.net/20140624102843593?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGFsZWl3YW5n/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
(3)在项目的AppDelegate中一般情况下有三个操作,第一是注册ShareSDK,第二是注册各个平台的账号,第三是关于微信等应用的回调处理。
(4)信息分享。
- -(IBAction)share:(id)sender{
- NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"card" ofType:@"png"];
-
- id<ISSContent> publishContent = [ShareSDK content:@"分享内容测试"
- defaultContent:@"默认分享内容测试,没内容时显示"
- image:[ShareSDK imageWithPath:imagePath]
- title:@"pmmq"
- url:@"http://www.sharesdk.cn"
- description:@"这是一条测试信息"
- mediaType:SSPublishContentMediaTypeNews];
- [ShareSDK showShareActionSheet:nil
- shareList:nil
- content:publishContent
- statusBarTips:YES
- authOptions:nil
- shareOptions: nil
- result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
- if (state == SSResponseStateSuccess)
- {
- NSLog(@"分享成功");
- }
- else if (state == SSResponseStateFail)
- {
- NSLog(@"分享失败");
- }
- }];
- }
(5)登录、登出、获取授权信息、关注制定微博
-
- #import "LoginViewController.h"
- #import <ShareSDK/ShareSDK.h>
-
- @interface LoginViewController ()
-
- -(IBAction)loginWithSina:(id)sender;
-
- -(IBAction)loginWithQQ:(id)sender;
-
- -(IBAction)loginoutWithSina:(id)sender;
-
- -(IBAction)loginoutWithQQ:(id)sender;
-
- -(IBAction)guanzhuUs:(id)sender;
-
- -(void)reloadStateWithType:(ShareType)type;
-
- @end
-
- @implementation LoginViewController
-
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- }
- return self;
- }
-
- - (void)viewDidLoad {
- [super viewDidLoad];
- }
-
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
-
- - (IBAction)loginWithSina:(id)sender {
- [ShareSDK getUserInfoWithType:ShareTypeSinaWeibo authOptions:nil result:^(BOOL result, id<ISSPlatformUser> userInfo, id<ICMErrorInfo> error) {
- NSLog(@"%d",result);
- if (result) {
-
-
- [self reloadStateWithType:ShareTypeSinaWeibo];
- }
- }];
- }
-
-
- -(IBAction)loginWithQQ:(id)sender{
- [ShareSDK getUserInfoWithType:ShareTypeQQSpace authOptions:nil result:^(BOOL result, id<ISSPlatformUser> userInfo, id<ICMErrorInfo> error) {
- NSLog(@"%d",result);
- if (result) {
-
-
- [self reloadStateWithType:ShareTypeQQSpace];
- }
- }];
- }
-
- -(IBAction)loginoutWithSina:(id)sender{
- [ShareSDK cancelAuthWithType:ShareTypeSinaWeibo];
- [self reloadStateWithType:ShareTypeSinaWeibo];
- }
-
- -(IBAction)loginoutWithQQ:(id)sender{
- [ShareSDK cancelAuthWithType:ShareTypeQQSpace];
- [self reloadStateWithType:ShareTypeQQSpace];
- }
-
- -(void)reloadStateWithType:(ShareType)type{
-
-
- id<ISSPlatformCredential> credential = [ShareSDK getCredentialWithType:type];
- UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"TEXT_TIPS", @"提示")
- message:[NSString stringWithFormat:
- @"uid = %@\ntoken = %@\nsecret = %@\n expired = %@\nextInfo = %@",
- [credential uid],
- [credential token],
- [credential secret],
- [credential expired],
- [credential extInfo]]
- delegate:nil
- cancelButtonTitle:NSLocalizedString(@"TEXT_KNOW", @"知道了")
- otherButtonTitles:nil];
- [alertView show];
- }
-
- -(IBAction)guanzhuUs:(id)sender{
- [ShareSDK followUserWithType:ShareTypeSinaWeibo
- field:@"ShareSDK"
- fieldType:SSUserFieldTypeName
- authOptions:nil
- viewDelegate:nil
- result:^(SSResponseState state, id<ISSPlatformUser> userInfo, id<ICMErrorInfo> error) {
- if (state == SSResponseStateSuccess) {
- NSLog(@"关注成功");
- } else if (state == SSResponseStateFail) {
- NSLog(@"%@", [NSString stringWithFormat:@"关注失败:%@", error.errorDescription]);
- }
- }];
- }
-
-
- @end
(5)你可能会看到一些应用需要第三方登录的,一种是弹出webView加载的新浪微博或者qq的网页授权,还有一种是跳转到本地的已经安装的新浪微博应用或者qq应用进行授权。第二种授权方式较SSO授权,体验会比较好一些,因为不需要用户输入新浪微博或QQ的用户名与密码。
第二种授权方式需要在plist中配置Scheme。SSO默认是打开的不需要配置。在AppDelegate中实现回调。
![技术分享](http://img.blog.csdn.net/20140624104923046?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGFsZWl3YW5n/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
(6)测试DEMO截图:
![技术分享](http://img.blog.csdn.net/20140624110628343?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGFsZWl3YW5n/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
![技术分享](http://img.blog.csdn.net/20140624110810859?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGFsZWl3YW5n/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
DEMO下载地址:http://download.csdn.net/download/daleiwang/7734321
IOS项目集成ShareSDK实现第三方登录、分享、关注等功能(转)
标签:string port copyto frame 关注 intro create nsstring 程序
原文地址:http://www.cnblogs.com/dreamDeveloper/p/6055820.html