當用戶經由過程點擊告訴新聞進入運用時
- (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點擊推送新聞跳轉處置】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!