統(tǒng)計(jì)基于SDK5.5.2版本
消息推送基于SDK3.2.3版本
分享基于SDK6.9.5版本
利用cocoapods導(dǎo)入相關(guān)依賴庫
####### 友盟基礎(chǔ)庫 #######
pod 'UMCCommon'
pod 'UMCSecurityPlugins' #pod ‘UMCSecurityPlugins’為安全組件解取,不需要開發(fā)者顯式調(diào)用步责,為開發(fā)者提供安全的數(shù)據(jù)環(huán)境,能有效的防止刷量和反作弊等行為禀苦,屬于可選項(xiàng)蔓肯,如果對(duì)App的數(shù)據(jù)安全性要求不高的話,可以去掉此pod振乏。
pod 'UMCCommonLog' #開發(fā)階段進(jìn)行調(diào)試SDK及相關(guān)功能使用蔗包,可在發(fā)布 App 前移除
####### 下面是分享的平臺(tái),用到哪個(gè)平臺(tái)導(dǎo)入哪個(gè)平臺(tái)慧邮,避免項(xiàng)目包過大 ######
# 集成微信(精簡(jiǎn)版0.2M)
pod 'UMCShare/Social/ReducedWeChat'
# 集成QQ/QZone/TIM(精簡(jiǎn)版0.5M)
pod 'UMCShare/Social/ReducedQQ'
# 集成新浪微博(精簡(jiǎn)版1M)
pod 'UMCShare/Social/ReducedSina'
###### 友盟統(tǒng)計(jì) #######
pod 'UMCAnalytics'#統(tǒng)計(jì) SDK
####### 友盟推送 #######
pod 'UMCPush' #Push SDK
如果分享還需要其他平臺(tái)的调限,請(qǐng)參考https://developer.umeng.com/docs/66632/detail/67204#h2--sdk5
一、友盟分享
導(dǎo)入上面的依賴庫后需要做以下幾件事情
1.1.配置白名單
<key>LSApplicationQueriesSchemes</key>
<array>
<!-- 微信 URL Scheme 白名單-->
<string>wechat</string>
<string>weixin</string>
<!-- 新浪微博 URL Scheme 白名單-->
<string>sinaweibohd</string>
<string>sinaweibo</string>
<string>sinaweibosso</string>
<string>weibosdk</string>
<string>weibosdk2.5</string>
<!-- QQ误澳、Qzone URL Scheme 白名單-->
<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>tim</string>
<string>timapi</string>
<string>timopensdkfriend</string>
<string>timwpa</string>
<string>timgamebindinggroup</string>
<string>timapiwallet</string>
<string>timOpensdkSSoLogin</string>
<string>wtlogintim</string>
<string>timopensdkgrouptribeshare</string>
<string>timopensdkapiV4</string>
<string>timgamebindinggroup</string>
<string>timopensdkdataline</string>
<string>wtlogintimV1</string>
<string>timapiV1</string>
<!-- 支付寶 URL Scheme 白名單-->
<string>alipay</string>
<string>alipayshare</string>
<!-- 釘釘 URL Scheme 白名單-->
<string>dingtalk</string>
<string>dingtalk-open</string>
</array>
太多不列了耻矮,可參考https://developer.umeng.com/docs/66632/detail/66825
1.2.配置URL Scheme
qq去這里申請(qǐng)
微信去這里申請(qǐng)
微博去這里申請(qǐng)
這些弄完了編譯一遍,不報(bào)錯(cuò)忆谓,就可以寫下面的代碼了裆装。
為了避免Appdelegate代碼過多,創(chuàng)建一個(gè)工具類倡缠,用于初始化友盟哨免、配置一些參數(shù)。
.h文件(之所以在.h文件中導(dǎo)入頭文件昙沦,是為了appdelegate中再次重復(fù)導(dǎo)入這些頭文件琢唾,也方便直接拖拽至其他項(xiàng)目中使用)
#import <Foundation/Foundation.h>
//需要的頭文件在這里導(dǎo)入,appdelegate中就不需要重新導(dǎo)入了
#import <UMCommon/UMCommon.h>
#import <UMShare/UMShare.h>
#import <UMPush/UMessage.h>
#import <UMAnalytics/MobClick.h>
#import <UMCommonLog/UMCommonLogHeaders.h>
#import <UserNotifications/UserNotifications.h>
@interface XBUMManager : NSObject
+(void)initUmManagerWithLaunchOptions:(NSDictionary *)launchOptions Delegate:(id)delegate;
@end
.m文件
#import "XBUMManager.h"
@interface XBUMManager ()<UNUserNotificationCenterDelegate>
@end
@implementation XBUMManager
+(void)initUmManagerWithLaunchOptions:(NSDictionary *)launchOptions Delegate:(id)delegate
{
// Override point for customization after application launch.
//開發(fā)者需要顯式的調(diào)用此函數(shù)桅滋,日志系統(tǒng)才能工作
[UMCommonLogManager setUpUMCommonLogManager];
[UMConfigure setLogEnabled:YES];//設(shè)置為YES, 輸出可供調(diào)試參考的log信息. 發(fā)布產(chǎn)品時(shí)必須設(shè)置為NO.
[UMConfigure initWithAppkey:@"5b039399f29d98151c000098" channel:@"App Store"];
// Share's setting
[self setupUSharePlatforms]; // required: setting platforms on demand
[MobClick setScenarioType:E_UM_GAME|E_UM_DPLUS];
[MobClick setCrashReportEnabled:YES];
// Push's basic setting
UMessageRegisterEntity * entity = [[UMessageRegisterEntity alloc] init];
//type是對(duì)推送的幾個(gè)參數(shù)的選擇慧耍,可以選擇一個(gè)或者多個(gè)身辨。默認(rèn)是三個(gè)全部打開,即:聲音芍碧,彈窗煌珊,角標(biāo)
entity.types = UMessageAuthorizationOptionBadge|UMessageAuthorizationOptionAlert|UNAuthorizationOptionSound;
if (@available(iOS 10.0, *)) {
[UNUserNotificationCenter currentNotificationCenter].delegate=delegate;
} else {
// Fallback on earlier versions
}
[UMessage registerForRemoteNotificationsWithLaunchOptions:launchOptions Entity:entity completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted) {
}else
{
}
}];
}
+ (void)setupUSharePlatforms{
/*
設(shè)置微信的appKey和appSecret
[微信平臺(tái)從U-Share 4/5升級(jí)說明]http://dev.umeng.com/social/ios/%E8%BF%9B%E9%98%B6%E6%96%87%E6%A1%A3#1_1
*/
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wx0688566e181a28b3" appSecret:@"c72a48c823b3a0589cf360bfb10a6fcf" redirectURL:nil];
/*
* 移除相應(yīng)平臺(tái)的分享,如微信收藏
*/
//[[UMSocialManager defaultManager] removePlatformProviderWithPlatformTypes:@[@(UMSocialPlatformType_WechatFavorite)]];
/* 設(shè)置分享到QQ互聯(lián)的appID
* U-Share SDK為了兼容大部分平臺(tái)命名泌豆,統(tǒng)一用appKey和appSecret進(jìn)行參數(shù)設(shè)置定庵,而QQ平臺(tái)僅需將appID作為U-Share的appKey參數(shù)傳進(jìn)即可。
100424468.no permission of union id
[QQ/QZone平臺(tái)集成說明]http://dev.umeng.com/social/ios/%E8%BF%9B%E9%98%B6%E6%96%87%E6%A1%A3#1_3
*/
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:@"1106906541"/*設(shè)置QQ平臺(tái)的appID*/ appSecret:@"CDHQsmIgZ7Nu6nPj" redirectURL:nil];
/*
設(shè)置新浪的appKey和appSecret
[新浪微博集成說明]http://dev.umeng.com/social/ios/%E8%BF%9B%E9%98%B6%E6%96%87%E6%A1%A3#1_2
*/
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:@"3921700954" appSecret:@"04b48b094faeb16683c32669824ebdad" redirectURL:@"https://sns.whalecloud.com/sina2/callback"];
/* 釘釘?shù)腶ppKey */
[[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_DingDing appKey:@"dingoalmlnohc0wggfedpk" appSecret:nil redirectURL:nil];
/* 支付寶的appKey */
[[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_AlipaySession appKey:@"2015111700822536" appSecret:nil redirectURL:nil];
/* 設(shè)置易信的appKey */
[[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_YixinSession appKey:@"yx35664bdff4db42c2b7be1e29390c1a06" appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];
/* 設(shè)置領(lǐng)英的appKey和appSecret */
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Linkedin appKey:@"81lcv9le14dpqi" appSecret:@"Po7OB9LxOaxhR9M3" redirectURL:@"https://api.linkedin.com/v1/people"];
/* 設(shè)置Twitter的appKey和appSecret */
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Twitter appKey:@"fB5tvRpna1CKK97xZUslbxiet" appSecret:@"YcbSvseLIwZ4hZg9YmgJPP5uWzd4zr6BpBKGZhf07zzh3oj62K" redirectURL:nil];
/* 設(shè)置Facebook的appKey和UrlString */
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Facebook appKey:@"506027402887373" appSecret:nil redirectURL:nil];
/* 設(shè)置Pinterest的appKey */
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Pinterest appKey:@"4864546872699668063" appSecret:nil redirectURL:nil];
/* dropbox的appKey */
[[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_DropBox appKey:@"k4pn9gdwygpy4av" appSecret:@"td28zkbyb9p49xu" redirectURL:@"https://mobile.umeng.com/social"];
/* vk的appkey */
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_VKontakte appKey:@"5786123" appSecret:nil redirectURL:nil];
}
@end
之后我們?cè)贏ppdelegate中只需要做很少的操作來初始化友盟了
初始化完了之后踪危,需要在appdelegate中蔬浙,對(duì)于分享回調(diào)需要做以下的幾件事
然后就可以在我們需要做分享操作的界面,處理業(yè)務(wù)邏輯了贞远。
到此畴博,分享的功能就完成了。
其他分享樣式請(qǐng)?jiān)敿?xì)拜讀官方文檔
二蓝仲、友盟統(tǒng)計(jì)
友盟統(tǒng)計(jì)俱病,一般項(xiàng)目只做最簡(jiǎn)單的統(tǒng)計(jì),注冊(cè)用戶、活躍用戶、崩潰日志收集這些基本就差不多了桐愉,如果需要收集用戶每個(gè)頁面點(diǎn)擊次數(shù),需要定制化收集這些信息溢吻,項(xiàng)目中的控制器最好都集成同一個(gè)baseViewController這樣方便操作,切記果元。
三促王、友盟推送
推送的方式比較多,推送所有設(shè)備而晒、推送指定設(shè)備硼砰、推送指定用戶等,這就需要根據(jù)業(yè)務(wù)需求來分門別類的處理欣硼。
下面說一下通用的代碼题翰,不管哪種推送業(yè)務(wù),都需要做的诈胜。
首先去https://mobile.umeng.com/apps/new這個(gè)地址豹障,注冊(cè)你的應(yīng)用,然后去蘋果開發(fā)者中心網(wǎng)站焦匈,將你項(xiàng)目的生產(chǎn)證書血公、發(fā)布證書的p12文件,放進(jìn)去缓熟,之后打開你項(xiàng)目的推送消息接收開關(guān)
完成了上面重要的步驟之后累魔,就可以寫下面的這些代碼了摔笤。
然后在appdelegate中做消息處理
如果以上內(nèi)容對(duì)你有幫助,請(qǐng)不要吝嗇你的star垦写。如有不對(duì)的地方吕世,還請(qǐng)指出來。
Demo集合