Added local push function to the game, write it down as a record
Local notifications are simpler than remote push.
Ios:
Add local push
/*Name: The unique name of the notification, which can be used as the ID of the notification to use message: the content of the notification time: When the notification is triggered (countdown time)*/voidSdkhelper::addlocalnotication (std::stringName, std::stringMessageintTime ) {uilocalnotification*localnotification =[[Uilocalnotification alloc] init]; if(Localnotification = =Nil) { return; } //Cancel the system notification of the same name first (avoid duplicate notifications)canclelocalnotication (name); //set the trigger time for local notifications (if triggered immediately, without setting), such as 20 seconds after triggeringLocalnotification.firedate =[NSDate Datewithtimeintervalsincenow:time]; //duplicate type of notificationLocalnotification.repeatinterval =Nscalendarunitday; //set the time zone for local notificationsLocalnotification.timezone =[Nstimezone Defaulttimezone]; //set the contents of a notificationLocalnotification.alertbody =[NSString StringWithUTF8String:message.c_str ()]; //set the caption of the Notification action buttonLocalnotification.alertaction =@"OK"; //set the sound of the reminder, you can add your own sound file, which is set as the default prompt soundLocalnotification.soundname =Uilocalnotificationdefaultsoundname; //set up information about the notification, this is important, you can add some of the marked content, easy to distinguish and get the notification information laternsstring* pushname = [NSString stringWithFormat:@"%s", Name.c_str ()]; Nsdictionary*infodic = [Nsdictionary dictionarywithobjectsandkeys:pushname,@"ID", [NSNumber Numberwithinteger:345635342],@" Time", [NSNumber Numberwithinteger:345635342],@"Affair.aid", nil]; Localnotification.userinfo=Infodic; //trigger a notification on a specified date[[UIApplication sharedapplication] schedulelocalnotification:localnotification]; [Localnotification release]; }voidSdkhelper::canclelocalnotication (std::stringname) { //get an array of all the pushes that existNsarray * Array =[[UIApplication sharedapplication] scheduledlocalnotifications]; //facilitate this array according to key to get the uilocalnotification we want for(Uilocalnotification * LocinchArray) { if([[Loc.userinfo Objectforkey:@"ID"] Isequaltostring:[nsstring stringWithFormat:@"%s", Name.c_str ()]) { //Cancel local Push[[UIApplication sharedapplication] cancellocalnotification:loc]; } }}
When the notification is triggered, if the app is running in the foreground, this method will be triggered, if the app is in the background, click on the notification will trigger,
- (void) Application: (UIApplication *) application didreceivelocalnotification: (uilocalnotification*) notification{NSLog (@"application did receive local notifications"); //cancel a specific local notification for(Uilocalnotification *notiinch[[UIApplication sharedapplication] scheduledlocalnotifications]) {NSString*NOTIID = noti.userinfo[@"ID"]; NSString*RECEIVENOTIID = notification.userinfo[@"ID"]; if([notiid isequaltostring:receivenotiid]) {[[UIApplication sharedapplication] Cancellocalnotification:noti Fication]; return; }} Application.applicationiconbadgenumber=0;}
Where Notification.userinfo is the custom content
iOS Local notifications