新浪微博 微信 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 导匣,
加入依賴系統(tǒng)庫
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>
分享
調(diào)取自定義模板
導入頭文件
import <UMSocialCore/UMSocialCore.h>
import <UShareUI/UShareUI.h>
遵守協(xié)議<UMSocialShareMenuViewDelegate>
ViewDidLoad 里面定義平臺
- (void)shareyoumeng
{
//設(shè)置用戶自定義的平臺
[UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_WechatSession), @(UMSocialPlatformType_WechatTimeLine), @(UMSocialPlatformType_QQ), @(UMSocialPlatformType_Qzone), @(UMSocialPlatformType_Sina), ]];
//設(shè)置分享面板的顯示和隱藏的代理回調(diào)
[UMSocialUIManager setShareMenuViewDelegate:self];
}
// 分享按鈕點擊事件
- (void)showBottomNormalView
{
[UMSocialShareUIConfig shareInstance].sharePageGroupViewConfig.sharePageGroupViewPostionType = UMSocialSharePageGroupViewPositionType_Bottom讯嫂;
[UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageItemStyleType = UMSocialPlatformItemViewBackgroudType_None;
[UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
//在回調(diào)里面獲得點擊的
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{
}
}];
}
//網(wǎng)頁分享
- (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType
{
//創(chuàng)建分享消息對象
UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
//創(chuàng)建網(wǎng)頁內(nèi)容對象
NSString* thumbURL = @"分享的圖片";
UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"分享的標題" descr:@"分享的內(nèi)容" thumImage:thumbURL];
//設(shè)置網(wǎng)頁地址
shareObject.webpageUrl = @"分享的鏈接";
//分享消息對象設(shè)置分享內(nèi)容對象
messageObject.shareObject = shareObject;
//調(diào)用分享接口
[[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;
//分享結(jié)果消息
UMSocialLogInfo(@"response message is %@",resp.message);
//第三方原始返回的數(shù)據(jù)
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;
// 第三方登錄數(shù)據(jù)(為空表示平臺未提供)
// 授權(quán)數(shù)據(jù)
NSLog(@" uid: %@", resp.uid);
NSLog(@" openid: %@", resp.openid);
NSLog(@" accessToken: %@", resp.accessToken);
NSLog(@" refreshToken: %@", resp.refreshToken);
NSLog(@" expiration: %@", resp.expiration);
// 用戶數(shù)據(jù)
NSLog(@" name: %@", resp.name);
NSLog(@" iconurl: %@", resp.iconurl);
NSLog(@" gender: %@", resp.gender);
// 第三方平臺SDK原始數(shù)據(jù)
NSLog(@" originalResponse: %@", resp.originalResponse);
}];
}