1.準(zhǔn)備app推送證書,證書創(chuàng)建
鑰匙串訪問->證書助理->從證書頒發(fā)機(jī)構(gòu)申請
2.上Account Developer 創(chuàng)建推送證書
2.1先創(chuàng)建應(yīng)用啼染,在創(chuàng)建推送證書
2.2 創(chuàng)建 有推送功能的開發(fā)或者發(fā)布證書
2.3 下載證書 —》再安裝證書 —導(dǎo)出證書—等待上傳到友盟
3.友盟創(chuàng)建應(yīng)用
4.項(xiàng)目配置
5.下載sdk集成
http://dev.umeng.com/sdk_integate/ios-integrate-guide/common
6.代碼
#import <UMCommon/UMCommon.h> // 公共組件是所有友盟產(chǎn)品的基礎(chǔ)組件悲没,必選
#import <UMPush/UMessage.h> // Push組件
#import <UserNotifications/UserNotifications.h>// Push組件必須的系統(tǒng)庫
#define UMAppKey @“5b06be93f43e485fae000077"
@interface AppDelegate ()<UNUserNotificationCenterDelegate>
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
// 配置友盟SDK產(chǎn)品并并統(tǒng)一初始化
[UMConfigureinitWithAppkey:UMAppKeychannel:@"App Store"];
// Push組件基本功能配置
[UNUserNotificationCentercurrentNotificationCenter].delegate= self;
UMessageRegisterEntity* entity = [[UMessageRegisterEntityalloc] init];
//type是對推送的幾個參數(shù)的選擇善绎,可以選擇一個或者多個祥楣。默認(rèn)是三個全部打開屎媳,即:聲音例隆,彈窗弥搞,角標(biāo)等
entity.types= UMessageAuthorizationOptionBadge|UMessageAuthorizationOptionAlert;
[UNUserNotificationCentercurrentNotificationCenter].delegate= self;
[UMessageregisterForRemoteNotificationsWithLaunchOptions:launchOptions Entity:entity completionHandler:^(BOOLgranted, NSError* _Nullableerror) {
if(granted) {
// 用戶選擇了接收Push消息
}else{
// 用戶拒絕接收Push消息
}
}];
// Override point for customization after application launch.
returnYES;
}
pragma -mark ———————————————————友盟推送代理————————————————————
//iOS10以下使用這兩個方法接收通知邮绿,
-(void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo fetchCompletionHandler:(void(^)(UIBackgroundFetchResult))completionHandler
{
[UMessagesetAutoAlert:NO];
//統(tǒng)計點(diǎn)擊數(shù)
[UMessagedidReceiveRemoteNotification:userInfo];
if([[[UIDevicecurrentDevice] systemVersion]intValue] < 10){
[UMessagedidReceiveRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
}
//iOS10新增:處理前臺收到通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter*)center willPresentNotification:(UNNotification*)notification withCompletionHandler:(void(^)(UNNotificationPresentationOptions))completionHandler{
NSDictionary* userInfo = notification.request.content.userInfo;
if([notification.request.triggerisKindOfClass:[UNPushNotificationTriggerclass]]) {
//應(yīng)用處于前臺時的遠(yuǎn)程推送接受
//關(guān)閉U-Push自帶的彈出框
[UMessagesetAutoAlert:NO];
//(前臺、后臺)的消息處理
[UMessagedidReceiveRemoteNotification:userInfo];
}else{
//應(yīng)用處于前臺時的本地推送接受
}
//當(dāng)應(yīng)用處于前臺時提示設(shè)置攀例,需要哪個可以設(shè)置哪一個
completionHandler(UNNotificationPresentationOptionSound|UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionAlert);
}
//iOS10新增:處理后臺點(diǎn)擊通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter*)center didReceiveNotificationResponse:(UNNotificationResponse*)response withCompletionHandler:(void(^)())completionHandler{
NSDictionary* userInfo = response.notification.request.content.userInfo;
if([response.notification.request.triggerisKindOfClass:[UNPushNotificationTriggerclass]]) {
//應(yīng)用處于后臺時的遠(yuǎn)程推送接受
//(前臺船逮、后臺)的消息處理
[UMessagedidReceiveRemoteNotification:userInfo];
if(userInfo.count>0){
//消息處理
NSLog(@"跳轉(zhuǎn)到你想要的");
}
}
else{ //應(yīng)用處于后臺時的本地推送接受
}
}
//打印設(shè)備注冊碼,需要在友盟測試設(shè)備上自己添加deviceToken
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
[UMessageregisterDeviceToken:deviceToken];
NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken success");
NSLog(@"deviceToken————>>>%@",[[[[deviceToken description] stringByReplacingOccurrencesOfString: @"<"withString: @""]
stringByReplacingOccurrencesOfString: @">"withString: @""]
stringByReplacingOccurrencesOfString: @" "withString: @""]);
}
//放上推送成功截圖????
別名推送
我的項(xiàng)目需求是登錄成功后綁定別名粤铭,退出登錄是移除別名
/*
* test:一般用用戶ID挖胃,后臺返回的用戶唯一標(biāo)識
*UMENGTEST:類型隨便填,要和后臺的類型一樣,這點(diǎn)要注意
*/
//多設(shè)備綁定別名
[UMessage addAlias:@"test@umeng.com" type:@"UMENGTEST" response:^(id _Nonnull responseObject, NSError * _Nonnull error) {
}];
//重置別名:只允許一個設(shè)備收到通知
+ (void)setAlias:(NSString *__nonnull )name type:(NSString * __nonnull)type response:(nullable void (^)(id __nonnull responseObject,NSError *__nonnull error))handle;
//移除別名
[UMessage removeAlias:@"test@umeng.com" type:@"UMENGTEST" response:^(id _Nonnull responseObject, NSError * _Nonnull error) {
}];
還未上線的應(yīng)用只能在測試環(huán)境收到推送酱鸭,所以要是后臺把環(huán)境改為正式環(huán)境收不到消息不要慌吗垮,要是真想在未上線也能收到正式環(huán)境推送,那么就搞個正式環(huán)境的來玩唄凹髓。
- 用AD Hoc方式打包項(xiàng)目烁登,上傳蒲公英進(jìn)行下載安裝,就可以收到正式環(huán)境的推送啦蔚舀。
- AD HOC 打包教程
- iOS 友盟推送(二)推送處理