ViewController.m
#import <UMSocialCore/UMSocialCore.h>
#import <UShareUI/UShareUI.h>
#pragma mark - 第三方平台登录
- (IBAction)loginButtonClick:(UIButton *)sender {
[self getUserInfoForPlatform:UMSocialPlatformType_WechatSession];
}
- (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);
}];
}
#pragma mark - 第三方平台分享
- (IBAction)shareButtonClick:(UIButton *)sender {
[self showShareMenuView];
}
- (void)showShareMenuView {
// 设置平台顺序,只显示设置列表中的应用
[UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_Sina),
@(UMSocialPlatformType_QQ),
@(UMSocialPlatformType_WechatSession),
@(UMSocialPlatformType_AlipaySession)]];
// 设置分享面板位置,底部 默认
[UMSocialShareUIConfig shareInstance].sharePageGroupViewConfig.sharePageGroupViewPostionType =
UMSocialSharePageGroupViewPositionType_Bottom;
// 设置分享按钮背景形状,有图片 没有圆背景
[UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageItemStyleType =
UMSocialPlatformItemViewBackgroudType_None;
// 添加自定义分享按钮
[UMSocialUIManager addCustomPlatformWithoutFilted:UMSocialPlatformType_UserDefine_Begin+2
withPlatformIcon:[UIImage imageNamed:@"icon_circle"]
withPlatformName:@"演示 icon"];
// 显示分享面板
[UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType,
NSDictionary *userInfo) {
// 根据获取的 platformType 确定所选平台进行下一步操作
[self shareTextToPlatformType:platformType];
// 在回调里面获得点击的
if (platformType == UMSocialPlatformType_UserDefine_Begin+2) {
NSLog(@"点击演示添加 Icon 后该做的操作");
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"添加自定义 icon"
message:@"具体操作方法请参考 UShareUI 内接口文档"
delegate:nil
cancelButtonTitle:NSLocalizedString(@"确定", nil)
otherButtonTitles:nil];
[alert show];
});
} else {
}
}];
}
// 设置分享内容
- (void)shareTextToPlatformType:(UMSocialPlatformType)platformType {
// 创建分享消息对象
UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
// 设置文本
messageObject.text = @"社会化组件 UShare 将各大社交平台接入您的应用,快速武装 App。";
// 调用分享接口,进行分享
[[UMSocialManager defaultManager] shareToPlatform:platformType
messageObject:messageObject
currentViewController:self
completion:^(id data, NSError *error) {
if (error) {
NSLog(@"************ Share fail with error %@ *********",error);
}else{
NSLog(@"response data is %@",data);
}
}];
}