IOS-click push message jump processing, ios-click message jump

Source: Internet
Author: User

IOS-click push message jump processing, ios-click message jump

When the user clicks the notification message to enter the application

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

The userInfo information of the push message is displayed.

NSDictionary* remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

Obtain the content of the push message. If remoteNotification is not empty, it indicates that the user enters through the PUSH message, then an attribute can be declared.

@property (nonatomic) BOOL isLaunchedByNotification;

It is used to identify whether a user enters the application by clicking the notification message. At this time,

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

It will be called, and iOS7 can be used.

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

Because MainViewController has been initialized when this method is called, we can register a listener for pushing messages in MainViewController to display the corresponding view, as shown below:

// Subscribe to the display view message. A branch view [[nsicationcenter center defacenter center] addObserver: self selector: @ selector (presentView :) name: @ "PresentView" object: nil] is directly opened. // The pop-up message box prompts you to subscribe to a notification message. This function is mainly used when you use an application. In the displayed dialog box [[nsnotifcenter center defacenter center] addObserver: self selector: @ selector (showNotification :) name: @ "Notification" object: nil];

Therefore, in the didReceiveRemoteNotification of AppDelegate, different display methods can be notified by judging isLaunchedByNotification.

The brain supplements the code that is pushed temporarily to play the audio without stopping the vibrate sound (not playing the music)

First include the header file

 #import <AudioToolbox/AudioToolbox.h>

Register a sound (in this example, the default 1007 is used directly)

@ Property (nonatomic, assign) SystemSoundID soundID; NSString * path = [[NSBundle mainBundle] pathForResource: soundName ofType: nil]; invoke (_ bridge CFURLRef) [NSURL fileURLWithPath: path], & _ soundID); resolve (_ soundID, NULL, NULL, soundCompleteCallback, NULL); // The core code can be repeated to execute AudioServicesPlaySystemSound (audio); AudioServicesPlaySystemSound (_ soundID ); // block is used for callback (_ soundID, NULL, NULL, soundCompleteCallback, NULL); function call void soundCompleteCallback (SystemSoundID soundID, void * clientData) {AudioServicesPlaySystemSound (callback ); audioServicesPlaySystemSound (soundID);} // stop playing-(void) Audio :( SystemSoundID) soundID {audio (kSystemSoundID_Vibrate); audio (soundID );}



 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.