When a user enters the application by clicking the notification message
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
launchOptions
There will be userInfo information for pushing messages in the push message, and we can pass
NSDictionary* remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
Get push message content. If remoteNotification is not empty, it means that the user enters through a push message, and then an attribute can be declared
@property (nonatomic) BOOL isLaunchedByNotification;
Used to identify whether the user enters this application through a click notification message. at this time,
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
Will definitely be called, iOS7 can be used
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
Because when this method is called, MainViewController has been initialized, we can register the listening of push messages in MainViewController to display the corresponding view, as follows:
//Subscribe to the display view message and a branch view will be opened directly[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(presentView:) name:@"PresentView" object:nil];//The pop-up message box prompts the user to have a subscription notification message. Mainly used when users use the application, prompt box pops up[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showNotification:) name:@"Notification" object:nil];
Therefore, in the didReceiveRemoteNotification of AppDelegate, you can notify different display methods by judging isLaunchedByNotification.
Imagine a code that plays the vibrating sound when the push comes (not playing music)
First include the header file
#import <AudioToolbox/>
Register a sound (in this case, default 1007 is used directly)
@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); // Core code can be executed repeatedlyAudioServicesPlaySystemSound(kSystemSoundID_Vibrate); AudioServicesPlaySystemSound(_soundID); // block is used for AudioServicesAddSystemSoundCompletion(_soundID, NULL, NULL, soundCompleteCallback, NULL); function callvoid soundCompleteCallback(SystemSoundID soundID,void * clientData) { AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); AudioServicesPlaySystemSound(soundID); } // Stop playback-(void)stopAlertSoundWithSoundID:(SystemSoundID)soundID { AudioServicesDisposeSystemSoundID(kSystemSoundID_Vibrate); AudioServicesDisposeSystemSoundID(soundID); AudioServicesRemoveSystemSoundCompletion(soundID); }
The above content is the relevant content of iOS click push message jump process introduced to you by the editor. I hope it will be helpful to everyone!