iOS點(diǎn)擊推送消息跳轉(zhuǎn)處理
當(dāng)用戶通過點(diǎn)擊通知消息進(jìn)入應(yīng)用時
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
launchOptions
中會有推送消息的userInfo信息,此時我們可以通過
NSDictionary* remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
獲得推送消息內(nèi)容。如果remoteNotification不為空,則說明用戶通過推送消息進(jìn)入,那么可以聲明一個屬性
@property (nonatomic) BOOL isLaunchedByNotification;
用于標(biāo)識用戶是否通過點(diǎn)擊通知消息進(jìn)入本應(yīng)用。此時,
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
一定會被調(diào)用,iOS7可以使用
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
因?yàn)榇朔椒ǖ恼{(diào)用時,MainViewController已經(jīng)被初始化,所以我們已經(jīng)可以在MainViewController注冊推送消息的監(jiān)聽,用于展示對應(yīng)的視圖,如下:
//訂閱展示視圖消息,將直接打開某個分支視圖 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(presentView:) name:@"PresentView" object:nil];//彈出消息框提示用戶有訂閱通知消息。主要用于用戶在使用應(yīng)用時,彈出提示框 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showNotification:) name:@"Notification" object:nil];
所以在AppDelegate的didReceiveRemoteNotification中可以通過判斷isLaunchedByNotification來通知不同的展示方法。
腦補(bǔ)一個推送來臨時,播放震動聲音不停止的代碼(不是播放音樂哦)
首先包含頭文件
#import <AudioToolbox/AudioToolbox.h>
注冊一段聲音(本例中直接使用默認(rèn)1007)
@property (nonatomic, assign) SystemSoundID soundID; NSString *path = [[NSBundle mainBundle] pathForResource:soundName ofType:nil]; AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &_soundID); AudioServicesAddSystemSoundCompletion(_soundID, NULL, NULL, soundCompleteCallback, NULL); // 核心代碼 可重復(fù)執(zhí)行 AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); AudioServicesPlaySystemSound(_soundID); // block 用于 AudioServicesAddSystemSoundCompletion(_soundID, NULL, NULL, soundCompleteCallback, NULL); 函數(shù)調(diào)用 void soundCompleteCallback(SystemSoundID soundID,void * clientData) { AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); AudioServicesPlaySystemSound(soundID); } // 停止播放 -(void)stopAlertSoundWithSoundID:(SystemSoundID)soundID { AudioServicesDisposeSystemSoundID(kSystemSoundID_Vibrate); AudioServicesDisposeSystemSoundID(soundID); AudioServicesRemoveSystemSoundCompletion(soundID); }
以上內(nèi)容是小編給大家介紹的iOS點(diǎn)擊推送消息跳轉(zhuǎn)處理的相關(guān)內(nèi)容,希望對大家有所幫助!
相關(guān)文章
ios 流媒體播放器實(shí)現(xiàn)流程及FreeStreamer的使用的示例
本篇文章主要介紹了ios 流媒體播放器實(shí)現(xiàn)流程及FreeStreamer的使用的示例代碼,非常具有實(shí)用價值,需要的朋友可以參考下2018-01-01iOS報Multiple?commands?produceMultiple錯誤的解決方案
這篇文章主要為大家介紹了iOS報Multiple?commands?produceMultiple錯誤的解決方案,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-11-11IOS 開發(fā)之UITableView 刪除表格單元寫法
這篇文章主要介紹了IOS 開發(fā)之UITableView 刪除表格單元寫法的相關(guān)資料,這里提供實(shí)例幫助大家實(shí)現(xiàn)該功能,希望能幫助到大家,需要的朋友可以參考下2017-08-08詳解iOS應(yīng)用UI開發(fā)中的九宮格坐標(biāo)計(jì)算與字典轉(zhuǎn)換模型
這篇文章主要介紹了iOS應(yīng)用UI開發(fā)中的九宮格坐標(biāo)計(jì)算與字典轉(zhuǎn)換模型,代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下2016-01-01Xcode中iOS應(yīng)用開發(fā)的一般項(xiàng)目目錄結(jié)構(gòu)和流程簡介
這篇文章主要介紹了Xcode中iOS應(yīng)用開發(fā)的一般項(xiàng)目目錄結(jié)構(gòu)和流程簡介,包括項(xiàng)目所需的一些平臺路徑如模擬器路徑等的介紹,需要的朋友可以參考下2016-02-02iOS手勢識別的詳細(xì)使用方法(拖動,縮放,旋轉(zhuǎn),點(diǎn)擊,手勢依賴,自定義手勢)
這篇文章主要介紹了iOS手勢識別的詳細(xì)使用方法(拖動,縮放,旋轉(zhuǎn),點(diǎn)擊,手勢依賴,自定義手勢),具有一定的參考價值,有需要的可以參考一下。2016-11-11iOS 泛型中nullable、null resettable、null kindof 用法詳解
這篇文章主要介紹了iOS 泛型中nullable、null resettable、null kindof 用法詳解的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-09-09