iOS集成友盟第三方分享

可以参考demo来做,demo是可以跑起来的,如果用demo,只需要把key和ID换掉就好了,点击下载demo

注册APPKey

友盟注册新AppKey拿到注册的AppKey

导入SDK

导入友盟提供的SDK,其目录结构如下
导入SDK
只需要将UMSocial导入项目中,接下来配置SDK

配置

Build Settings->Other Linker Flags加入-ObjC
如图所示
Other Linker Flags

设置Web支持HTTP

因为iOS目前不支持HTTP,所以在web登录中还需要配置HTTP,配置方法如下:
Info-plist文件中添加App Transport Security Settings其类型为Dictionary,然后在App Transport Security Settings中添加Allow Arbitrary Loads,其类型为BOOL,将其修改为YES

配置成功如下:
配置Info.plist文件

添加依赖库
  • 友盟依赖库

    • libsqlite3.tbd
    • CoreGraphics.framework
  • 微信依赖库

    • SystemConfiguration.framework
    • CoreTelephony.framework
    • libsqlite3.tbd
    • libc++.tbd
    • libz.tbd
  • QQ依赖库
    • SystemConfiguration.framework
    • libc++.tbd
  • 微博依赖库
    • SystemConfiguration.framework
    • CoreTelephony.framework
    • ImageIO.framework
    • libsqlite3.tbd
    • libz.tbd
      导入的库如图:
      导入的库
设置白名单&Schemes


  • 设置SSO白名单

配置白名单小技巧,右击Info.plist文件,选择文本编辑器打开,将下面代码直接copy进去,没必要为这些东西浪费时间
<key>LSApplicationQueriesSchemes</key>
<array>
    <!-- 微信 URL Scheme 白名单-->
    <string>wechat</string>
    <string>weixin</string>

    <!-- 新浪微博 URL Scheme 白名单-->
    <string>sinaweibohd</string>
    <string>sinaweibo</string>
    <string>sinaweibosso</string>
    <string>weibosdk</string>
    <string>weibosdk2.5</string>

    <!-- QQ、Qzone URL Scheme 白名单-->
    <string>mqqapi</string>
    <string>mqq</string>
    <string>mqqOpensdkSSoLogin</string>
    <string>mqqconnect</string>
    <string>mqqopensdkdataline</string>
    <string>mqqopensdkgrouptribeshare</string>
    <string>mqqopensdkfriend</string>
    <string>mqqopensdkapi</string>
    <string>mqqopensdkapiV2</string>
    <string>mqqopensdkapiV3</string>
    <string>mqqopensdkapiV4</string>
    <string>mqzoneopensdk</string>
    <string>wtloginmqq</string>
    <string>wtloginmqq2</string>
    <string>mqqwpa</string>
    <string>mqzone</string>
    <string>mqzonev2</string>
    <string>mqzoneshare</string>
    <string>wtloginqzone</string>
    <string>mqzonewx</string>
    <string>mqzoneopensdkapiV2</string>
    <string>mqzoneopensdkapi19</string>
    <string>mqzoneopensdkapi</string>
    <string>mqqbrowser</string>
    <string>mttbrowser</string>
</array>
  • 配置Schemes
    来到Info->URL Types配置Schemes
    QQ空间的是将QQ的ID改为16进制,QQID原本是8进制,在前面+QQ,不足八位数前面+0
平台APPKey举例注意
QQ100424468tencent100424468QQ需要添加tencent
QQ空间918d3f7QQ0918d3f7不足八位前面+0
微信wxdc1e388c3822c80bwxdc1e388c3822c80b微信直接用
微博3921700954wb3921700954微博添加wb

配置如图所示:

配置Schemes

注册平台

导入SDK头文件#import <UMSocialCore/UMSocialCore.h>

在AppDelegate.m文件中配置,在

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  

方法中注册友盟的AppKey

 //设置AppKey,是在友盟注册之后给到的key
    [[UMSocialManager defaultManager] setUmSocialAppkey:UMKEY];

然后注册各个平台的AppKey和AppID

//    setPlaform是要注册的平台

    /* 微信聊天 */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wxdc1e388c3822c80b" appSecret:@"3baf1193c85774b3fd9d18447d76cab0" redirectURL:@"http://mobile.umeng.com/social"];

    /*QQ*/
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:@"1106152098"  appSecret:@"KexLaOiU6VVzxgQb" redirectURL:@"http://mobile.umeng.com/social"];

    /*
     注**
     redirectURL必须要和微博设置的回调一致
     */
    /* 新浪 */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:@"1234957746"  appSecret:@"b3564b393bfcb42672d8e84f084ea550" redirectURL:@"https://sns.whalecloud.com/sina2/callback"];
设置回调

在AppDelegate.m中添加以下方法设置回调

// 支持所有iOS系统版本回调
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{

    BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url sourceApplication:sourceApplication annotation:annotation];
    if (!result) {
        // 其他如支付等SDK的回调
    }
    return result;
}
使用

导入SDK头文件#import <UMSocialCore/UMSocialCore.h>

- (void)share{
/*
     创建网页内容对象
     根据不同需求设置不同分享内容,一般为图片,标题,描述,url
     */
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"分享标题" descr:@"分享的内容的描述" thumImage:[UIImage imageNamed:@"head@2x"]];

    //设置网页地址
    shareObject.webpageUrl = @"http://www.talkmoney.cn";


    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;

    /**
     设置分享

     @param data 分享返回信息
     @param error 失败信息
     @param UMSocialPlatformType 分享平台
     */
    [[UMSocialManager defaultManager] shareToPlatform:UMSocialPlatformType_QQ messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            UMSocialLogInfo(@"************Share fail with error %@*********",error);
        }else{
            if ([data isKindOfClass:[UMSocialShareResponse class]]) {
                UMSocialShareResponse *resp = data;
                //分享结果消息
                UMSocialLogInfo(@"response message is %@",resp.message);
                //第三方原始返回的数据
                UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
            }else{
                UMSocialLogInfo(@"response data is %@",data);
            }
        }
    }];

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值