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

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

主模塊(必須)

pod 'mob_sharesdk'

UI模塊(非必須,需要用到ShareSDK提供的分享菜單欄和分享編輯頁面需要以下1行)

pod 'mob_sharesdk/ShareSDKUI'

平臺(tái)SDK模塊(對(duì)照一下平臺(tái),需要的加上。如果只需要QQ、微信、新浪微博,只需要以下3行)

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

pod 'mob_sharesdk/ShareSDKPlatforms/WeChatFull' //(微信sdk帶支付的命令,和上面不帶支付的不能共存,只能選擇一個(gè))

pod 'mob_sharesdk/ShareSDKPlatforms/SMS'//短信
二.配置集成
1.設(shè)置ShareSDK的appkey

在項(xiàng)目工程的Info.plist 中如圖增加 MOBAppkey 和 MOBAppSecret 兩個(gè)字段
1224_446_285.69.png

提示:如果您同時(shí)多個(gè)MOBSDK產(chǎn)品 在info.plist中的設(shè)置一次就可以了。
- (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];

   
    // 定制新浪微博的分享內(nèi)容
    [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];
    
     // 定制短信分享內(nèi)容
    [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;
        }
    }];
}

白名單配置,各參數(shù)參考mod文檔http://www.mob.com/wiki/detailed?wiki=ShareSDK_ios_whitelist_first&id=14

Info.plist添加 LSApplicationQueriesSchemes 類型Array


WeChat3b3e6687c3afe49f1993d8d6c97262fa.png

各平臺(tái)URL Scheme配置參考:http://www.mob.com/wiki/detailed?wiki=ShareSDK_ios_urlscheme_two&id=14

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容