ShareSDK 分享到微信,微博,QQ,短信

1)按需要在Podfile 文件中添加命令:

主模块(必须)

pod 'mob_sharesdk'

UI模块(非必须,需要用到ShareSDK提供的分享菜单栏和分享编辑页面需要以下1行)

pod 'mob_sharesdk/ShareSDKUI'

平台SDK模块(对照一下平台,需要的加上。如果只需要QQ、微信、新浪微博,只需要以下3行)

pod 'mob_sharesdk/ShareSDKPlatforms/QQ'
pod 'mob_sharesdk/ShareSDKPlatforms/SinaWeibo'
pod 'mob_sharesdk/ShareSDKPlatforms/WeChat' //(微信sdk不带支付的命令)

pod 'mob_sharesdk/ShareSDKPlatforms/WeChatFull' //(微信sdk带支付的命令,和上面不带支付的不能共存,只能选择一个)

pod 'mob_sharesdk/ShareSDKPlatforms/SMS'//短信
二.配置集成
1.设置ShareSDK的appkey

在项目工程的Info.plist 中如图增加 MOBAppkey 和 MOBAppSecret 两个字段
1224_446_285.69.png

提示:如果您同时多个MOBSDK产品 在info.plist中的设置一次就可以了。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
              [self regist];
              return YES;
}
+ (void)regist {
    
    [ShareSDK registPlatforms:^(SSDKRegister *platformsRegister) {
        
        [platformsRegister setupSMSOpenCountryList:NO];
        //QQ
        [platformsRegister setupQQWithAppId:@"" appkey:@""];
        //微信
        [platformsRegister setupWeChatWithAppId:@"" appSecret:@""];

        //新浪
         [platformsRegister setupSinaWeiboWithAppkey:@"" appSecret:@"" redirectUrl:@"http://www.sharesdk.cn"];
    }];
}

+ (void)share {

    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    NSURL *url = [NSURL URLWithString:@"http://www.mob.com/"];
    [params SSDKSetupShareParamsByText:@"test"
                                images:[UIImage imageNamed:@"AppIcon.png"]
                                   url:url
                                 title:@"title"
                                  type:SSDKContentTypeAuto];

   
    // 定制新浪微博的分享内容
    [params SSDKSetupSinaWeiboShareParamsByText: ChangeStr(@"testWB,%@",url)
                                                  title:nil
                                                 images:[UIImage imageNamed:@"AppIcon.png"]
                                                  video:nil
                                                    url:nil
                                               latitude:0
                                              longitude:0
                                               objectID:0
                                         isShareToStory:false
                                                   type:SSDKContentTypeAuto];
    
     // 定制短信分享内容
    [params SSDKSetupSMSParamsByText:ChangeStr(@"testSMS,%@",url)title:nil images:nil attachments:nil recipients:nil type:SSDKContentTypeText];
   

    [ShareSDK showShareActionSheet:nil
                      customItems:nil
                      shareParams:params
               sheetConfiguration:nil
                   onStateChanged:^(SSDKResponseState state,
                                    SSDKPlatformType platformType,
                                    NSDictionary *userData,
                                    SSDKContentEntity *contentEntity,
                                    NSError *error,
                                    BOOL end)
    {

        switch (state) {

            case SSDKResponseStateSuccess:
            NSLog(@"成功");//成功
                break;
            case SSDKResponseStateFail:
                 {
            NSLog(@"--%@",error.description);
               //失败
               break;
          }
            case SSDKResponseStateCancel:
                break;
            default:
            break;
        }
    }];
}

白名单配置,各参数参考mod文档http://www.mob.com/wiki/detailed?wiki=ShareSDK_ios_whitelist_first&id=14

Info.plist添加 LSApplicationQueriesSchemes 类型Array


WeChat3b3e6687c3afe49f1993d8d6c97262fa.png

各平台URL Scheme配置参考:http://www.mob.com/wiki/detailed?wiki=ShareSDK_ios_urlscheme_two&id=14

你可能感兴趣的:(ShareSDK 分享到微信,微博,QQ,短信)