第三方分享有很多第三方集成平臺-友盟,mob,極光等
還有一種是下載各個第三方平臺的sdk各個集成
無論是用原平臺sdk還是第三方平臺sdk我們都需要項目配置所以第一步通用配置
先用平臺各個集成然后在第三方平臺集成這篇不涉及各平臺申請appid和key過程
第一步項目配置
1)設(shè)置白名單 targets-info—URL Types中
2)在plist中添加數(shù)組字段LSApplicationQueriesSchemes
技巧:點plist右擊可以open as切換到code模式添加
<key>LSApplicationQueriesSchemes</key>
<array>
<string>wechat</string>
<string>weixin</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>
<string>sinaweibohd</string>
<string>sinaweibo</string>
<string>sinaweibosso</string>
<string>weibosdk</string>
<string>weibosdk2.5</string>
</array>
3)導入依賴庫SystemConfiguration
4)build settings ->other linker flags中-ObjC
第二部 集成步驟(qq,微信,微博)
QQ
qqsdk包經(jīng)常變以前會有一個素材包我剛下載的沒有了
//http://wiki.connect.qq.comqq開發(fā)文檔
//http://wiki.open.qq.com/wiki/【QQ登錄】SDK下載
qq:TencentOpenAPI.framework
import <TencentOpenAPI/TencentOAuth.h>
在 AppDelegate應(yīng)用入口或者需要分享的地方添加
由于分享不需要授權(quán)回調(diào)沒有申請代理
TencentOAuth *te =[[TencentOAuth alloc]initWithAppId:QQAPIID andDelegate:nil];
在viewcontroller
import <TencentOpenAPI/TencentOAuth.h>
import <TencentOpenAPI/QQApiInterfaceObject.h>
import <TencentOpenAPI/QQApiInterface.h>
//初始化;
TencentOAuth *ten = [[TencentOAuth alloc]initWithAppId:QQAPIID andDelegate:nil];
//分享類型枚舉
QQApiURLObject *urlobject = [QQApiURLObject objectWithURL:[NSURL URLWithString:@"http://open.qq.com"] title:@"你好" description:@"我好喜歡你" previewImageData:UIImageJPEGRepresentation([UIImage imageNamed:@"tubiao"], 1) targetContentType:QQApiURLTargetTypeNews];
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:urlobject];
//分享好友
QQApiSendResultCode sent = [QQApiInterface sendReq:req];
//空間
// QQApiSendResultCode sent = [QQApiInterface SendReqToQZone:req];
———————————
微博
https://github.com/sinaweibosdk/weibo_ios_sdk
下載weibosdk將libWeiboSDK導入項目
導入依賴庫
QuartzCore.framework
ImageIO.framework
SystemConfiguration.framework
Security.framework
CoreTelephony.framework
CoreText.framework
UIKit.framework
Foundation.framework
CoreGraphics.framework
libz.dylib
libsqlite3.dylib
坑點:官方文檔漏掉一個系統(tǒng)庫
photos.framework!
不加入的會報錯如下
Undefined symbols for architecture arm64:
"OBJC_CLASS$_PHAsset", referenced from:
最后在
方法:程序 Target->Buid Settings->Linking 下 OtherLinker Flags 項添加 -ObjC。
不添加匯報一個bug
[UIDevice wbsdk_plainDeviceID]: unrecognized selector sent to class 0x1a8382ab0
使用
在Appdelegate程序里入口處獲知使用分享的地方添加
[WeiboSDK registerApp:WB_KEY];
//打開調(diào)試窗口
[WeiboSDK enableDebugMode:YES];
WBAuthorizeRequest *WbAuthRequest = [WBAuthorizeRequest request];
//授權(quán)回調(diào)
WbAuthRequest.redirectURI = @"http://www.baidu.com";
WbAuthRequest.scope = @"all";
//分享文本信息
WBMessageObject *message = [WBMessageObject message];
message.text = @"你好我想你";
// 消息的圖片內(nèi)容中,圖片數(shù)據(jù)不能為空并且大小不能超過10M
WBImageObject *imageObject = [WBImageObject object];
imageObject.imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"tubiao"], 1.0);
message.imageObject = imageObject;
WBSendMessageToWeiboRequest *request = [WBSendMessageToWeiboRequest requestWithMessage:message];
[WeiboSDK sendRequest:request];
完成了
注意:如果項目中需要使用登入功能那么要在appdelegate中的openurl代理方法中接收回調(diào)
微信
官方下載資源包:手動導入獲知pod
手動導入將資源包中的
libWeChatSDK.a
WechatAuthSDK.h
WXApi.h
WXApiObject.h
添加以下依賴庫
SystemConfiguration.framework,
libz.dylib,
libsqlite3.0.dylib,
libc++.dylib,
Security.framework,
CoreTelephony.framework,
CFNetwork.framework。
最后在
Other Linker Flags"中加入-ObjC -all_load
注意:官方文檔和他們的案列demo寫錯了注意
//微信
import "WXApi.h"
[WXApi registerApp:@"wx0105fa0fa5ed69a1"];
//創(chuàng)建發(fā)送對象實例
SendMessageToWXReq *sendReq = [[SendMessageToWXReq alloc] init];
sendReq.bText = NO;//不使用文本信息
sendReq.scene = 1;//0 = 好友列表 1 = 朋友圈 2 = 收藏
//創(chuàng)建分享內(nèi)容對象
WXMediaMessage *urlMessage = [WXMediaMessage message];
urlMessage.title = @"你好";//分享標題
urlMessage.description = @"測試";//分享描述
[urlMessage setThumbImage:[UIImage imageNamed:@"tubiao"]];//分享圖片,使用SDK的setThumbImage方法可壓縮圖片大小
// /創(chuàng)建多媒體對象
WXWebpageObject *webObj = [WXWebpageObject object];
webObj.webpageUrl = @"www.baidu.com";//分享鏈接
//完成發(fā)送對象實例
urlMessage.mediaObject = webObj;
sendReq.message = urlMessage;
//發(fā)送分享信息
[WXApi sendReq:sendReq];
—————完成
友盟分享
導入友盟sdk
Other Linker Flags"中加入-ObjC
添加依賴庫
libsqlite3.tbd
CoreGraphics.framework
· 微信(完整版)-精簡版無需添加以下依賴庫
SystemConfiguration.framework
CoreTelephony.framework
libsqlite3.tbd
libc++.tbd
libz.tbd
· QQ/QZone/TIM(完整版)-精簡版無需添加以下依賴庫
SystemConfiguration.framework
libc++.tbd
· 新浪微博(完整版)-精簡版無需添加以下依賴庫
SystemConfiguration.framework
CoreTelephony.framework
ImageIO.framework
libsqlite3.tbd
libz.tbd
· Twitter
CoreData.framework
· 短信
MessageUI.framework
在delegate中
import <UMSocialCore/UMSocialCore.h>
初始化um
/* 打開調(diào)試日志 */
[[UMSocialManager defaultManager] openLog:YES];
/* 設(shè)置友盟appkey */
[[UMSocialManager defaultManager] setUmSocialAppkey:USHARE_DEMO_APPKEY];
//設(shè)置平臺key 和secret
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"id" appSecret:@“key” redirectURL:nil];
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
{
//6.3的新的API調(diào)用,是為了兼容國外平臺(例如:新版facebookSDK,VK等)的調(diào)用[如果用6.2的api調(diào)用會沒有回調(diào)],對國內(nèi)平臺沒有影響
BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url options:options];
if (!result) {
// 其他如支付等SDK的回調(diào)
}
return result;
} - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url];
if (!result) {
// 其他如支付等SDK的回調(diào)
}
return result;
}
分享界面vc中添加
import <UShareUI/UShareUI.h>
//創(chuàng)建分享消息對象
UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
//設(shè)置文本
messageObject.text = @"社會化組件UShare將各大社交平臺接入您的應(yīng)用,快速武裝App。";
//規(guī)劃平臺
__weak typeof(self) weakSelf = self;
[UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
[weakSelf shareTextToPlatformType:platformType];
}];
-(void)shareTextToPlatformType:(UMSocialPlatformType)platformtype{
//創(chuàng)建分享消息對象
UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
//設(shè)置文本
messageObject.text = @"社會化組件UShare將各大社交平臺接入您的應(yīng)用,快速武裝App。";
//調(diào)用分享接口
[[UMSocialManager defaultManager] shareToPlatform:platformtype messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
if (error) {
NSLog(@"************失敗錯誤碼%@*********",error);
}else{
NSLog(@"response data%@",data);
}
}];
}
第三方登入友盟
在分享的基礎(chǔ)上
-
(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.unionGender); // 第三方平臺SDK原始數(shù)據(jù) NSLog(@" originalResponse: %@", resp.originalResponse);}];
}