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

首頁 > 系統 > iOS > 正文

iOS點擊推送消息跳轉處理

2019-10-21 18:54:51
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了iOS點擊推送消息跳轉處理 的相關資料,需要的朋友可以參考下
 

當用戶通過點擊通知消息進入應用時

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

launchOptions

中會有推送消息的userInfo信息,此時我們可以通過

NSDictionary* remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 

獲得推送消息內容。如果remoteNotification不為空,則說明用戶通過推送消息進入,那么可以聲明一個屬性

@property (nonatomic) BOOL isLaunchedByNotification; 

用于標識用戶是否通過點擊通知消息進入本應用。此時,

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

一定會被調用,iOS7可以使用

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

因為此方法的調用時,MainViewController已經被初始化,所以我們已經可以在MainViewController注冊推送消息的監聽,用于展示對應的視圖,如下:

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

所以在AppDelegate的didReceiveRemoteNotification中可以通過判斷isLaunchedByNotification來通知不同的展示方法。

腦補一個推送來臨時,播放震動聲音不停止的代碼(不是播放音樂哦)

首先包含頭文件

#import <AudioToolbox/AudioToolbox.h> 

注冊一段聲音(本例中直接使用默認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); // 核心代碼 可重復執行AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);AudioServicesPlaySystemSound(_soundID);// block 用于 AudioServicesAddSystemSoundCompletion(_soundID, NULL, NULL, soundCompleteCallback, NULL); 函數調用void soundCompleteCallback(SystemSoundID soundID,void * clientData){AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);AudioServicesPlaySystemSound(soundID);}// 停止播放-(void)stopAlertSoundWithSoundID:(SystemSoundID)soundID {AudioServicesDisposeSystemSoundID(kSystemSoundID_Vibrate);AudioServicesDisposeSystemSoundID(soundID);AudioServicesRemoveSystemSoundCompletion(soundID);}

以上內容是小編給大家介紹的iOS點擊推送消息跳轉處理的相關內容,希望對大家有所幫助!



注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 衡阳市| 怀仁县| 嘉峪关市| 襄垣县| 建平县| 彰化市| 武平县| 龙南县| 滨海县| 托里县| 开平市| 纳雍县| 马尔康县| 和政县| 高雄县| 绵阳市| 长葛市| 白山市| 军事| 县级市| 甘孜县| 诸暨市| 贵定县| 大城县| 安远县| 永登县| 黄骅市| 神农架林区| 广东省| 镇雄县| 巨鹿县| 九龙城区| 临汾市| 深水埗区| 新化县| 农安县| 灌阳县| 丰台区| 金阳县| 贵州省| 尉氏县|