iOS 三方分享登录推送

玩 iOS 友盟分享

2018-05-25  本文已影响43人  HH思無邪

1.按着官方集成文档,一步一步做

https://developer.umeng.com/docs/66632/detail/66825

  1. //友盟分享极简版
#import “UMSocialQQHandler.h"    //QQ极简
#import “UMSocialWechatHandler.h" //微信极简
#define UMAppKeychannel @"kahafgjfgjhhjgas12314" //友盟AppKey
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
    // 配置友盟SDK产品并并统一初始化
    [UMConfigureinitWithAppkey:UMAppKeychannel:@"App Store"];
    //分享
    [[UMSocialManagerdefaultManager] setUmSocialAppkey: UMAppKeychannel];
 //如果要分享http的图片地址,手动将其关闭
    [UMSocialGlobal shareInstance].isUsingHttpsWhenShareContent = NO;

    /* 设置微信的appKey和appSecret */
   [[UMSocialManagerdefaultManager] setPlaform:UMSocialPlatformType_WechatSessionappKey:weixinkeyappSecret:@"d46a7567c7f639b26ba5cdbd22"redirectURL:@"[http://mobile.umeng.com/social](http://mobile.umeng.com/social)"];
    /*设置QQ平台的appID*/
  [[UMSocialManagerdefaultManager] setPlaform:UMSocialPlatformType_QQappKey:@"471357"appSecret:nilredirectURL:@"[http://mobile.umeng.com/social](http://mobile.umeng.com/social)"];
    // Override point for customization after application launch.
 /* 设置新浪的appKey和appSecret */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:Sina_key  appSecret:@"8bc00fa74e82aed5a1caca9891947" redirectURL:@"https://sns.whalecloud.com/sina2/callback"];
    returnYES;

}

//分享回调

-(BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url

{

    BOOLresult = [[UMSocialManagerdefaultManager] handleOpenURL:url];

    if(!result) {

        // 其他如支付等SDK的回调

    }

    return result;

}

//实现文件 viewcontroller.m 里

#import <UShareUI/UShareUI.h>

//响应事件中 ->显示分享面板

[UMSocialUIManagershowShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformTypeplatformType, NSDictionary*userInfo)
 {
        // 根据获取的platformType确定所选平台进行下一步操作
        [selfshareWebPageToPlatformType:platformType];//新增代码
    }];

//定义实现的方法

- (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType

{

    //创建分享消息对象

    UMSocialMessageObject*messageObject = [UMSocialMessageObjectmessageObject];

    //创建网页内容对象

    NSString* thumbURL =  @"[https://mobile.umeng.com/images/pic/home/social/img-1.png](https://mobile.umeng.com/images/pic/home/social/img-1.png)";

    UMShareWebpageObject*shareObject = [UMShareWebpageObjectshareObjectWithTitle:@"欢迎使用【友盟+】社会化组件U-Share"descr:@"欢迎使用【友盟+】社会化组件U-Share,SDK包最小,集成成本最低,助力您的产品开发、运营与推广!"thumImage:thumbURL];

    //设置网页地址

    shareObject.webpageUrl= @"[http://mobile.umeng.com/social](http://mobile.umeng.com/social)";

    //分享消息对象设置分享内容对象

    messageObject.shareObject= shareObject;

    //调用分享接口

   [[UMSocialManagerdefaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:selfcompletion:^(iddata, NSError*error) {

        if(error) {

            UMSocialLogInfo(@"************Share fail with error %@*********",error);

        }else{

            if([data isKindOfClass:[UMSocialShareResponseclass]]) {

                UMSocialShareResponse*resp = data;

                //分享结果消息

                UMSocialLogInfo(@"response message is %@",resp.message);

                //第三方原始返回的数据

                UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);

            }else{
                UMSocialLogInfo(@"response data is %@",data);
            }
        }
        NSLog(@"分享出错%@",error);//修改代码
    }];
}

实现自定义分享板块


Simulator Screen Shot - iPhone X - 2018-08-08 at 23.24.42.png

点击不同按钮 响应相应的类型 然后发起分享

            [TSFiveUSocialShareView showWithWeiBo:^{//新浪
                  UMSocialPlatformType platformType = UMSocialPlatformType_Sina;
                 [self shareWebPageToPlatformType:platformType];
            } qq:^{//QQ
                 UMSocialPlatformType platformType = UMSocialPlatformType_QQ;
             [self shareWebPageToPlatformType:platformType];
            } qqZone:^{//qq空间
                UMSocialPlatformType platformType = UMSocialPlatformType_Qzone;
                [self shareWebPageToPlatformType:platformType];
            } weiChat:^{//微信
                UMSocialPlatformType platformType = UMSocialPlatformType_WechatSession;
                [self shareWebPageToPlatformType:platformType];
            } weiChatFrend:^{//朋友圈
                UMSocialPlatformType platformType = UMSocialPlatformType_WechatTimeLine;
                [self shareWebPageToPlatformType:platformType];
            }];

分享实现传递类型参数

- (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType
{
   //创建分享消息对象
   UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
   if (platformType == UMSocialPlatformType_Sina) {//新浪做特殊处理
       //设置文本
       messageObject.text = [NSString stringWithFormat:@"%@%@",self.model.title,self.model.url];
       //创建图片内容对象
       UMShareImageObject *shareObject = [[UMShareImageObject alloc] init];
       //图片内容
       [shareObject setShareImage:self.model.icon];
       //分享消息对象设置分享内容对象
       messageObject.shareObject = shareObject;
   }else{
       UMShareWebpageObject *shareObject = [[UMShareWebpageObject alloc] init];
       shareObject.webpageUrl =self.model.url;
       shareObject.descr = self.model.info;
       shareObject.title = self.model.title;
       shareObject.thumbImage =self.model.icon;
       //分享消息对象设置分享内容对象
       messageObject.shareObject = shareObject;
   }
   //调用分享接口
   [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
       if (error) {
          TSLog(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);
           }
       }
   }];
}
上一篇下一篇

猜你喜欢

热点阅读