最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS10全新推送功能實(shí)現(xiàn)代碼

 更新時(shí)間:2016年09月19日 14:06:57   作者:u012847940  
這篇文章主要為大家詳細(xì)介紹了iOS10全新推送功能實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

從iOS8.0開(kāi)始推送功能的實(shí)現(xiàn)在不斷改變,功能也在不斷增加,iOS10又出來(lái)了一個(gè)推送插件的開(kāi)發(fā)(見(jiàn)最后圖),廢話不多說(shuō)直接上代碼: 

#import <UserNotifications/UserNotifications.h>
 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 // Override point for customization after application launch.
 
 /* APP未啟動(dòng),點(diǎn)擊推送消息的情況下 iOS10遺棄UIApplicationLaunchOptionsLocalNotificationKey,使用代理UNUserNotificationCenterDelegate方法didReceiveNotificationResponse:withCompletionHandler:獲取本地推送
 */
// NSDictionary *localUserInfo = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
// if (localUserInfo) {
// NSLog(@"localUserInfo:%@",localUserInfo);
// //APP未啟動(dòng),點(diǎn)擊推送消息
// }
 NSDictionary *remoteUserInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
 if (remoteUserInfo) {
 NSLog(@"remoteUserInfo:%@",remoteUserInfo);
 //APP未啟動(dòng),點(diǎn)擊推送消息,iOS10下還是跟以前一樣在此獲取
 }
 [self registerNotification];
 return YES;
}
 

注冊(cè)推送方法的改變:

新增庫(kù) #import <UserNotifications/UserNotifications.h>  推送單列UNUserNotificationCenter 等API 

- (void)registerNotification{
 /*
 identifier:行為標(biāo)識(shí)符,用于調(diào)用代理方法時(shí)識(shí)別是哪種行為。
 title:行為名稱(chēng)。
 UIUserNotificationActivationMode:即行為是否打開(kāi)APP。
 authenticationRequired:是否需要解鎖。
 destructive:這個(gè)決定按鈕顯示顏色,YES的話按鈕會(huì)是紅色。
 behavior:點(diǎn)擊按鈕文字輸入,是否彈出鍵盤(pán)
 */
 UNNotificationAction *action1 = [UNNotificationAction actionWithIdentifier:@"action1" title:@"策略1行為1" options:UNNotificationActionOptionForeground];
 /*iOS9實(shí)現(xiàn)方法
 UIMutableUserNotificationAction * action1 = [[UIMutableUserNotificationAction alloc] init];
 action1.identifier = @"action1";
 action1.title=@"策略1行為1";
 action1.activationMode = UIUserNotificationActivationModeForeground;
 action1.destructive = YES;
 */
 
 UNTextInputNotificationAction *action2 = [UNTextInputNotificationAction actionWithIdentifier:@"action2" title:@"策略1行為2" options:UNNotificationActionOptionDestructive textInputButtonTitle:@"textInputButtonTitle" textInputPlaceholder:@"textInputPlaceholder"];
 /*iOS9實(shí)現(xiàn)方法
 UIMutableUserNotificationAction * action2 = [[UIMutableUserNotificationAction alloc] init];
 action2.identifier = @"action2";
 action2.title=@"策略1行為2";
 action2.activationMode = UIUserNotificationActivationModeBackground;
 action2.authenticationRequired = NO;
 action2.destructive = NO;
 action2.behavior = UIUserNotificationActionBehaviorTextInput;//點(diǎn)擊按鈕文字輸入,是否彈出鍵盤(pán)
 */
 
 UNNotificationCategory *category1 = [UNNotificationCategory categoryWithIdentifier:@"Category1" actions:@[action2,action1] minimalActions:@[action2,action1] intentIdentifiers:@[@"action1",@"action2"] options:UNNotificationCategoryOptionCustomDismissAction];
 // UIMutableUserNotificationCategory * category1 = [[UIMutableUserNotificationCategory alloc] init];
 // category1.identifier = @"Category1";
 // [category1 setActions:@[action2,action1] forContext:(UIUserNotificationActionContextDefault)];
 
 UNNotificationAction *action3 = [UNNotificationAction actionWithIdentifier:@"action3" title:@"策略2行為1" options:UNNotificationActionOptionForeground];
 // UIMutableUserNotificationAction * action3 = [[UIMutableUserNotificationAction alloc] init];
 // action3.identifier = @"action3";
 // action3.title=@"策略2行為1";
 // action3.activationMode = UIUserNotificationActivationModeForeground;
 // action3.destructive = YES;
 
 UNNotificationAction *action4 = [UNNotificationAction actionWithIdentifier:@"action4" title:@"策略2行為2" options:UNNotificationActionOptionForeground];
 // UIMutableUserNotificationAction * action4 = [[UIMutableUserNotificationAction alloc] init];
 // action4.identifier = @"action4";
 // action4.title=@"策略2行為2";
 // action4.activationMode = UIUserNotificationActivationModeBackground;
 // action4.authenticationRequired = NO;
 // action4.destructive = NO;
 
 UNNotificationCategory *category2 = [UNNotificationCategory categoryWithIdentifier:@"Category2" actions:@[action3,action4] minimalActions:@[action3,action4] intentIdentifiers:@[@"action3",@"action4"] options:UNNotificationCategoryOptionCustomDismissAction];
 // UIMutableUserNotificationCategory * category2 = [[UIMutableUserNotificationCategory alloc] init];
 // category2.identifier = @"Category2";
 // [category2 setActions:@[action4,action3] forContext:(UIUserNotificationActionContextDefault)];
 
 
 [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObjects:category1,category2, nil]];
 [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert completionHandler:^(BOOL granted, NSError * _Nullable error) {
 NSLog(@"completionHandler");
 }];
 /*iOS9實(shí)現(xiàn)方法
 UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound) categories:[NSSet setWithObjects: category1,category2, nil]];

 [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
 */
 [[UIApplication sharedApplication] registerForRemoteNotifications];
 
 
 [UNUserNotificationCenter currentNotificationCenter].delegate = self;
}

代理方法的改變:

 一些本地和遠(yuǎn)程推送的回調(diào)放在了同一個(gè)代理方法

#pragma mark -

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED{
 NSLog(@"didRegisterUserNotificationSettings");
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken NS_AVAILABLE_IOS(3_0){
 NSLog(@"deviceToken:%@",deviceToken);
 NSString *deviceTokenSt = [[[[deviceToken description]
   stringByReplacingOccurrencesOfString:@"<" withString:@""]
  stringByReplacingOccurrencesOfString:@">" withString:@""]
  stringByReplacingOccurrencesOfString:@" " withString:@""];
 NSLog(@"deviceTokenSt:%@",deviceTokenSt);
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error NS_AVAILABLE_IOS(3_0){
 NSLog(@"didFailToRegisterForRemoteNotificationsWithError:%@",error);
}

/*iOS9使用方法
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo NS_DEPRECATED_IOS(3_0, 10_0, "Use UserNotifications Framework's -[UNUserNotificationCenterDelegate willPresentNotification:withCompletionHandler:] or -[UNUserNotificationCenterDelegate didReceiveNotificationResponse:withCompletionHandler:] for user visible notifications and -[UIApplicationDelegate application:didReceiveRemoteNotification:fetchCompletionHandler:] for silent remote notifications"){
 
}
*/

- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
 NSLog(@"willPresentNotification:%@",notification.request.content.title);
 
 // 這里真實(shí)需要處理交互的地方
 // 獲取通知所帶的數(shù)據(jù)
 NSString *notMess = [notification.request.content.userInfo objectForKey:@"aps"];
 
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
 //在沒(méi)有啟動(dòng)本App時(shí),收到服務(wù)器推送消息,下拉消息會(huì)有快捷回復(fù)的按鈕,點(diǎn)擊按鈕后調(diào)用的方法,根據(jù)identifier來(lái)判斷點(diǎn)擊的哪個(gè)按鈕
 NSString *notMess = [response.notification.request.content.userInfo objectForKey:@"aps"];
 NSLog(@"didReceiveNotificationResponse:%@",response.notification.request.content.title);
// response.notification.request.identifier
}

//遠(yuǎn)程推送APP在前臺(tái)
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
 NSLog(@"didReceiveRemoteNotification:%@",userInfo);
}

/*
- (void)application:(UIApplication *)application handleActionWithIdentifier:(nullable NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler NS_DEPRECATED_IOS(8_0, 10_0, "Use UserNotifications Framework's -[UNUserNotificationCenterDelegate didReceiveNotificationResponse:withCompletionHandler:]") __TVOS_PROHIBITED
{
 
}
*/
/*
// 本地通知回調(diào)函數(shù),當(dāng)應(yīng)用程序在前臺(tái)時(shí)調(diào)用
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification NS_DEPRECATED_IOS(4_0, 10_0, "Use UserNotifications Framework's -[UNUserNotificationCenterDelegate willPresentNotification:withCompletionHandler:] or -[UNUserNotificationCenterDelegate didReceiveNotificationResponse:withCompletionHandler:]") __TVOS_PROHIBITED{
 NSLog(@"didReceiveLocalNotification:%@",notification.userInfo);
 
 
 // 這里真實(shí)需要處理交互的地方
 // 獲取通知所帶的數(shù)據(jù)
 NSString *notMess = [notification.userInfo objectForKey:@"aps"];
 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"本地通知(前臺(tái))"
    message:notMess
    delegate:nil
   cancelButtonTitle:@"OK"
   otherButtonTitles:nil];
 [alert show];
 
 // 更新顯示的徽章個(gè)數(shù)
 NSInteger badge = [UIApplication sharedApplication].applicationIconBadgeNumber;
 badge--;
 badge = badge >= 0 ? badge : 0;
 [UIApplication sharedApplication].applicationIconBadgeNumber = badge;
 
 // 在不需要再推送時(shí),可以取消推送
 [FirstViewController cancelLocalNotificationWithKey:@"key"];

}


- (void)application:(UIApplication *)application handleActionWithIdentifier:(nullable NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler NS_DEPRECATED_IOS(8_0, 10_0, "Use UserNotifications Framework's -[UNUserNotificationCenterDelegate didReceiveNotificationResponse:withCompletionHandler:]") __TVOS_PROHIBITED
{
 //在非本App界面時(shí)收到本地消息,下拉消息會(huì)有快捷回復(fù)的按鈕,點(diǎn)擊按鈕后調(diào)用的方法,根據(jù)identifier來(lái)判斷點(diǎn)擊的哪個(gè)按鈕,notification為消息內(nèi)容
 NSLog(@"%@----%@",identifier,notification);
 completionHandler();//處理完消息,最后一定要調(diào)用這個(gè)代碼塊
}
*/

 還有推送插件開(kāi)發(fā): 類(lèi)似iOS tody widget插件開(kāi)發(fā)

 

本文已被整理到了《iOS推送教程》,歡迎大家學(xué)習(xí)閱讀。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • iOS實(shí)現(xiàn)換膚功能的簡(jiǎn)單處理框架(附源碼)

    iOS實(shí)現(xiàn)換膚功能的簡(jiǎn)單處理框架(附源碼)

    這篇文章主要給大家介紹了關(guān)于iOS實(shí)現(xiàn)換膚功能的簡(jiǎn)單處理框架,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-02-02
  • ios12中遇到的帶input彈窗的錯(cuò)位問(wèn)題的解決方法

    ios12中遇到的帶input彈窗的錯(cuò)位問(wèn)題的解決方法

    這篇文章主要介紹了ios12中遇到的帶input彈窗的錯(cuò)位問(wèn)題的解決方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2019-05-05
  • iOS實(shí)現(xiàn)一個(gè)意見(jiàn)反饋類(lèi)型的輸入欄

    iOS實(shí)現(xiàn)一個(gè)意見(jiàn)反饋類(lèi)型的輸入欄

    這篇文章主要給大家介紹了關(guān)于利用iOS實(shí)現(xiàn)一個(gè)意見(jiàn)反饋類(lèi)型的輸入欄,通過(guò)文中實(shí)現(xiàn)的輸入欄會(huì)用戶一個(gè)很好的體驗(yàn)效果,文中給了詳細(xì)的示例代碼,需要的朋友可以參考借鑒,下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-10-10
  • 解決iOS13 無(wú)法獲取WiFi名稱(chēng)(SSID)問(wèn)題

    解決iOS13 無(wú)法獲取WiFi名稱(chēng)(SSID)問(wèn)題

    這篇文章主要介紹了解決iOS13 無(wú)法獲取WiFi名稱(chēng)(SSID)問(wèn)題,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-09-09
  • iOS實(shí)現(xiàn)點(diǎn)擊微信頭像(放大、縮放、保存)效果

    iOS實(shí)現(xiàn)點(diǎn)擊微信頭像(放大、縮放、保存)效果

    最近公司產(chǎn)品需要實(shí)現(xiàn)點(diǎn)擊個(gè)人主頁(yè)頭像可以放大頭像、縮放頭像、保存頭像效果(和點(diǎn)擊微信個(gè)人頭像類(lèi)似),故找個(gè)時(shí)間實(shí)現(xiàn)一下,記錄下來(lái),供自己查看也給有需要的大家做個(gè)參考。下面來(lái)一起看看吧。
    2017-03-03
  • IOS中的target action控件的實(shí)現(xiàn)

    IOS中的target action控件的實(shí)現(xiàn)

    這篇文章主要介紹了IOS中的target action控件的實(shí)現(xiàn)的相關(guān)資料,這里提供實(shí)現(xiàn)target action的簡(jiǎn)單實(shí)例幫助大家學(xué)習(xí)理解該如何實(shí)現(xiàn),需要的朋友可以參考下
    2017-08-08
  • iOS動(dòng)態(tài)調(diào)整UILabel高度的幾種方法

    iOS動(dòng)態(tài)調(diào)整UILabel高度的幾種方法

    在iOS編程中UILabel是一個(gè)常用的控件,下面這篇文章主要給大家介紹了關(guān)于iOS動(dòng)態(tài)調(diào)整UILabel高度的幾種方法,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-12-12
  • iOS微信支付交互圖分析

    iOS微信支付交互圖分析

    這篇文章主要為大家詳細(xì)分析了iOS微信支付交互圖,針對(duì)微信支付的流程圖進(jìn)行解析,感興趣的小伙伴們可以參考一下
    2016-08-08
  • iOS實(shí)現(xiàn)視頻播放全屏和取消全屏功能

    iOS實(shí)現(xiàn)視頻播放全屏和取消全屏功能

    這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)視頻播放全屏和取消全屏功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-02-02
  • IOS 開(kāi)發(fā)之UILabel 或者 UIButton加下劃線鏈接

    IOS 開(kāi)發(fā)之UILabel 或者 UIButton加下劃線鏈接

    這篇文章主要介紹了IOS 開(kāi)發(fā)之UILabel 或者 UIButton加下劃線鏈接的相關(guān)資料,需要的朋友可以參考下
    2017-07-07

最新評(píng)論

呼和浩特市| 濉溪县| 林州市| 元江| 普定县| 天全县| 庐江县| 芦溪县| 乡城县| 确山县| 宁陕县| 达州市| 绥棱县| 若尔盖县| 义马市| 门头沟区| 马关县| 越西县| 青川县| 霍州市| 梁平县| 含山县| 嵊州市| 隆安县| 广安市| 长寿区| 潮安县| 资源县| 三门峡市| 宁化县| 遂平县| 铁岭县| 闸北区| 枝江市| 天长市| 乌审旗| 宜兰县| 武穴市| 当涂县| 舞钢市| 壶关县|