国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > iOS > 正文

iOS點(diǎn)擊推送消息跳轉(zhuǎn)處理

2020-02-19 15:48:11
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

當(dāng)用戶點(diǎn)擊頁(yè)面都會(huì)收到推送消息,當(dāng)我們想打開app的時(shí)候要跳轉(zhuǎn)到相應(yīng)的界面,這需要在AppDelegate中處理,今天武林技術(shù)頻道小編為大家?guī)?lái)iOS點(diǎn)擊推送消息跳轉(zhuǎn)處理,一起了解一下吧!

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions

launchOptions

中會(huì)有推送消息的userInfo信息,此時(shí)我們可以通過(guò)

NSDictionary* remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 

獲得推送消息內(nèi)容。如果remoteNotification不為空,則說(shuō)明用戶通過(guò)推送消息進(jìn)入,那么可以聲明一個(gè)屬性

@property (nonatomic) BOOL isLaunchedByNotification; 

用于標(biāo)識(shí)用戶是否通過(guò)點(diǎn)擊通知消息進(jìn)入本應(yīng)用。此時(shí),

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo 

一定會(huì)被調(diào)用,iOS7可以使用

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler 

因?yàn)榇朔椒ǖ恼{(diào)用時(shí),MainViewController已經(jīng)被初始化,所以我們已經(jīng)可以在MainViewController注冊(cè)推送消息的監(jiān)聽,用于展示對(duì)應(yīng)的視圖,如下:

//訂閱展示視圖消息,將直接打開某個(gè)分支視圖[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(presentView:) name:@"PresentView" object:nil];//彈出消息框提示用戶有訂閱通知消息。主要用于用戶在使用應(yīng)用時(shí),彈出提示框[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showNotification:) name:@"Notification" object:nil]; 

所以在AppDelegate的didReceiveRemoteNotification中可以通過(guò)判斷isLaunchedByNotification來(lái)通知不同的展示方法。

腦補(bǔ)一個(gè)推送來(lái)臨時(shí),播放震動(dòng)聲音不停止的代碼(不是播放音樂哦)

首先包含頭文件

#import <AudioToolbox/AudioToolbox.h> 

注冊(cè)一段聲音(本例中直接使用默認(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);}

以上是武林技術(shù)頻道小編為大家?guī)?lái)的iOS點(diǎn)擊推送消息跳轉(zhuǎn)處理的內(nèi)容,大家都閱讀完了吧,更多的知識(shí)盡在武林技術(shù)頻道哦。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 沙洋县| 兴宁市| 开封市| 通化县| 万载县| 商都县| 拜泉县| 绵竹市| 普安县| 仪陇县| 通州区| 平和县| 遵义市| 广东省| 定安县| 邓州市| 军事| 临猗县| 银川市| 浦城县| 临泽县| 阿瓦提县| 通河县| 大港区| 敦煌市| 昌黎县| 株洲县| 嘉荫县| 永州市| 裕民县| 渭源县| 秦安县| 洛隆县| 广西| 武安市| 东辽县| 固阳县| 湛江市| 石渠县| 阿鲁科尔沁旗| 巴青县|