When the user clicks on the received push message, I want to open the app and jump to the corresponding interface, which requires the agent method to be processed in the appdelegate.
When the user clicks the push message to open the app, it calls
-(BOOL) Application: (uiapplication*) Application didfinishlaunchingwithoptions: (nsdictionary*) launchOptions
There will be userinfo information for the push message in the Launchoptions, at which point we can
nsdictionary* remotenotification = [Launchoptions Objectforkey:uiapplicationlaunchoptionsremotenotificationkey];
Gets the content to push, and if remotenotification is not empty, then the user is pushed into the app, you can declare a property
@property (nonatomic) BOOL islaunchedbynotification;
Used to identify whether the user entered the app by clicking the notification message. At this time
-(void) Application: (uiapplication*) Application didreceiveremotenotification: (nsdictionary*) UserInfo
Must be called, iOS7 can be used
-(void) Application: (uiapplication*) Application didreceiveremotenotification: (nsdictionary*) UserInfo Fetchcompletionhandler: (void (^) (uibackgroundfetchresult)) Completionhandler
Since this method is called, Mainviewcontroller has already been initialized, so we can register a push message listener in Mainviewcontroller to show the corresponding view, as follows:
// Subscribe to the Presentation view message and open a branch view directly [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (presentview:) Name:@ " Presentview"object: nil"; // a pop-up message box prompts the user for a subscription notification message. Primarily for users when using the app, pop-up prompts [[Nsnotificationcenter defaultcenter] addobserver:self selector: @selector (shownotification :) Name:@ "Notification"object: nil];
Therefore, in the Appdelegate didreceiveremotenotification can be judged by the islaunchedbynotification to inform different presentation methods.
A push to temporarily, play vibrate sound does not stop the code, not play music OH
First include the header file
#import <AudioToolbox/AudioToolbox.h>
Register a sound (the default 1007 is used directly in this example)
@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); //The core code can be executed repeatedlyAudioservicesplaysystemsound (ksystemsoundid_vibrate); Audioservicesplaysystemsound (_soundid);//block for audioservicesaddsystemsoundcompletion (_soundid, NULL, NULL, soundcompletecallback, NULL); function callvoidSoundcompletecallback (Systemsoundid Soundid,void*clientdata) {Audioservicesplaysystemsound (ksystemsoundid_vibrate); Audioservicesplaysystemsound (Soundid);}//Stop playing-(void) Stopalertsoundwithsoundid: (Systemsoundid) Soundid {audioservicesdisposesystemsoundid (kSystemSoundID_Vibrate ); Audioservicesdisposesystemsoundid (Soundid); Audioservicesremovesystemsoundcompletion (Soundid);}
Add a little tricks, with friends to open the video push, when applied to the background, may also be killed, I am very strange, why this push notification, sound and vibration can stop, always remind users, and iOS8 on the top of the notice banner is always displayed, It won't stop until the user clicks into the app, how does this work?
In fact, with a less than 30s audio file is done
This document refers to the public number: iOS development
Click Push message Jump Processing (IOS)