iOS友盟第三方登录及分享

新浪微博 微信 QQ

友盟SDK下载地址: http://dev.umeng.com/social/ios/sdk-download 下载简洁版

将下面的拖入项目中:
UMSocial - U-Share SDK核心目录
UMSocialSDK - U-Share SDK核心framework
UMSocialUI - U-Share 分享UI资源、分享面板framework
SocialLibraries - 所选择下载的第三方平台SDK及U-Share链接库

在Build Settings ----Linking------Other Linker Flags加入-ObjC ,

加入依赖系统库
libsqlite3.tbd
CoreGraphics.framework

配置OSS白名单
<key>LSApplicationQueriesSchemes</key>
<array>

<string>wechat</string>
<string>weixin</string>

<string>sinaweibohd</string>
<string>sinaweibo</string>
<string>sinaweibosso</string>
<string>weibosdk</string>
<string>weibosdk2.5</string>

<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>

分享

调取自定义模板

导入头文件
import <UMSocialCore/UMSocialCore.h>
import <UShareUI/UShareUI.h>
遵守协议<UMSocialShareMenuViewDelegate>
ViewDidLoad 里面定义平台

- (void)shareyoumeng
{
    //设置用户自定义的平台
 [UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_WechatSession), @(UMSocialPlatformType_WechatTimeLine),  @(UMSocialPlatformType_QQ), @(UMSocialPlatformType_Qzone), @(UMSocialPlatformType_Sina), ]];
 //设置分享面板的显示和隐藏的代理回调
  [UMSocialUIManager setShareMenuViewDelegate:self];
}

// 分享按钮点击事件
- (void)showBottomNormalView
{
[UMSocialShareUIConfig shareInstance].sharePageGroupViewConfig.sharePageGroupViewPostionType = UMSocialSharePageGroupViewPositionType_Bottom;
[UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageItemStyleType = UMSocialPlatformItemViewBackgroudType_None;
[UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
//在回调里面获得点击的
if (platformType == UMSocialPlatformType_WechatSession)
{
[self shareWebPageToPlatformType:UMSocialPlatformType_WechatSession];
}
else if (platformType == UMSocialPlatformType_WechatTimeLine)
{
[self shareWebPageToPlatformType:UMSocialPlatformType_WechatTimeLine];
}
else if (platformType == UMSocialPlatformType_QQ)
{
[self shareWebPageToPlatformType:UMSocialPlatformType_QQ];
}
else if (platformType == UMSocialPlatformType_Qzone)
{
[self shareWebPageToPlatformType:UMSocialPlatformType_Qzone];
}
else if (platformType == UMSocialPlatformType_Sina)
{
[self shareWebPageToPlatformType:UMSocialPlatformType_Sina];
}
else{
}
}];
}

//网页分享
- (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType
{
//创建分享消息对象
UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];

//创建网页内容对象
NSString* thumbURL =  @"分享的图片";
UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"分享的标题" descr:@"分享的内容" thumImage:thumbURL];
//设置网页地址
shareObject.webpageUrl = @"分享的链接";

//分享消息对象设置分享内容对象
messageObject.shareObject = shareObject;

//调用分享接口

[[UMSocialManager defaultManager] shareToPlatform:platformType 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);
        }
    }
    [self alertWithError:error];
}];
}


- (void)alertWithError:(NSError *)error
{
NSString *result = nil;
if (!error) {
    
result = [NSString stringWithFormat:@"Share succeed"];
}
else{
NSMutableString *str = [NSMutableString string];
if (error.userInfo) {
  for (NSString *key in error.userInfo) {
 [str appendFormat:@"%@ = %@\n", key, error.userInfo[key]];
 }
   }
if (error) {
 result = [NSString stringWithFormat:@"Share fail with error code: %d\n%@",(int)error.code, str];
}
else{
  result = [NSString stringWithFormat:@"Share fail"];
}
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"share" message:result  delegate:nil  cancelButtonTitle:NSLocalizedString(@"sure", @"确定") otherButtonTitles:nil];
[alert show];
}

登录

QQ登录 [self getUserInfoForPlatform:UMSocialPlatformType_QQ];
微信登录 [self getUserInfoForPlatform:UMSocialPlatformType_WechatSession];
微博登录 [self getUserInfoForPlatform:UMSocialPlatformType_Sina];

  - (void)getUserInfoForPlatform:(UMSocialPlatformType)platformType
{
[[UMSocialManager defaultManager] getUserInfoWithPlatform:platformType currentViewController:self completion:^(id result, NSError *error) {

   UMSocialUserInfoResponse *resp = result;
  // 第三方登录数据(为空表示平台未提供)
 // 授权数据
  NSLog(@" uid: %@", resp.uid);
  NSLog(@" openid: %@", resp.openid);
  NSLog(@" accessToken: %@", resp.accessToken);
  NSLog(@" refreshToken: %@", resp.refreshToken);
  NSLog(@" expiration: %@", resp.expiration);
// 用户数据
  NSLog(@" name: %@", resp.name);
  NSLog(@" iconurl: %@", resp.iconurl);
  NSLog(@" gender: %@", resp.gender);
 // 第三方平台SDK原始数据
  NSLog(@" originalResponse: %@", resp.originalResponse);

}];
}          
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容