The app update prompt in remote notifications.

Source: Internet
Author: User

appdelegate.m//sdjk////Created by Jobs on 6/13/16.//Copyright (c) com. Flintinfo.demo. All rights reserved.//#import "AppDelegate.h" #import <SMS_SDK/SMSSDK.h> #import " YTKNetworkConfig.h "#import" YTKUrlArgumentsFilter.h "#import <BaiduMapAPI/BMKMapManager.h> #import < baidumapapi/bmklocationservice.h> #import <BaiduMapAPI/BMapKit.h> #import "MessageBox.h" #import " AudioPlayerController.h "#import" JPUSHService.h "#define Smsappkey @" 14de71d0c204e "#define Smsappsecret @" 3b28f08695e5241779e274a9c05970e1 "@interface appdelegate () <bmkgeneraldelegate, Bmklocationservicedelegate,    jpushregisterdelegate>{Bmkmapmanager *_mapmanager; Bmklocationservice *_locservice;} @end @implementation Appdelegate#pragma mark-bmkgeneraldelegate/** * Return network error * @param ierror error number */-(void) Ongetnetworksta TE: (int) ierror{}/** * Return Authorization validation error * @param ierror error Number: Validation passed for 0 o'clock, specific participation Bmkpermissioncheckresultcode */-(void) ongetpermissions Tate: (int) ierror{} #pragma mark-bmklocationservicedelegate/** * This function is called when the location is about to start */-(void) willstartlocatinguser{}/** * This function is called when the location is stopped */-(void) didstoplocatinguser{}/** * After the user orientation is updated, this function is called * @param userlocation New user location */-(void) didupdateuserheading: (bmkuserlocation *) userlocation{}/** * After the user location is updated, this function is called * @param userlocation New user location */-(void) Didupdatebmkuserlocation: (Bmkuserlocation *    ) userlocation{self.locationcoordinate = userLocation.location.coordinate; if (Cllocationcoordinate2disvalid (self.locationcoordinate) = = YES) {NSLog (@ "Didupdateuserlocation lat%f,long%f        ", userlocation.location.coordinate.latitude,userlocation.location.coordinate.longitude);    [_locservice Stopuserlocationservice]; }}-(cllocationdistance) Getcllocationdistance: (cllocationcoordinate2d) Coordinatea TheTowCoordinate: (    cllocationcoordinate2d) coordinateb{cllocationdistance dis;    dis = bmkmetersbetweenmappoints (bmkmappointforcoordinate (Coordinatea), Bmkmappointforcoordinate (CoordinateB)); return dis;} /** * This function is called after a failed location *@param error Error number */-(void) Didfailtolocateuserwitherror: (Nserror *) error{} #pragma mark-viewcontroller-(void) Setupre questfilters{nsstring *appversion = [[NSBundle mainbundle] infodictionary] objectforkey:@ "    Cfbundleshortversionstring "]; Ytknetworkconfig *config = [Ytknetworkconfig sharedinstance]; #if!defined (TESTAPI) Config.baseurl = @ "https://121.    42.156.51/";    Config.serverip = @ "https://121.42.156.51";    Config.serverport = nil;    #else Config.baseurl = @ "https://121.42.156.51:10443/";    Config.serverip = @ "https://121.42.156.51";    Config.serverport = @ "10443";                                                                                    #endif ytkurlargumentsfilter *urlfilter = [ytkurlargumentsfilter filterwitharguments:@{@ "version": AppVersion, @ "UIID": [Uidevice Currentdevice].identifier  Forvendor.uuidstring, @ "name": [Uidevice    Currentdevice].name,                                                                                @ "model": [Uidevice Currentdevice].model, @ "Appkey": @ "297ff4a97fcda4bc0ecf0bb18168    034A "}]; [Config addurlfilter:urlfilter];} -(void) Initjpush: (nsdictionary*) launchoptions{//nsstring *advertisingid = [[[Asidentifiermanager SharedManager]    Advertisingidentifier] uuidstring]; required//if ([[Uidevice currentdevice].systemversion Floatvalue] >= 10.0)//{////jpushregisterentity * entity = [[Jpushregisterentity alloc] init];////entity.types = unauthorizationoptionalert| unauthorizationoptionbadge|    unauthorizationoptionsound;////[Jpushservice registerforremotenotificationconfig:entity delegate:self];//}// else if ([[Uidevice currentdevice].systemversion Floatvalue] >= 8.0) {//can add custom CategoRies [Jpushservice registerforremotenotificationtypes: (Uiusernotificationtypebadge |                                                          Uiusernotificationtypesound |    Uiusernotificationtypealert) Categories:nil]; The else {//categories must be nil [jpushservice registerforremotenotificationtypes: (Uiremotenotificationtypeba                                                          Dge |                                                          Uiremotenotificationtypesound |    Uiremotenotificationtypealert) Categories:nil]; }//required//init Push (2.1.5 version of the SDK new registration method, changed to reportable IDFA, if not using IDFA direct nil)//If you need to continue to use Pushconfig.plist file declaration Appke    Y, and so on, please use [Jpushservice setupwithoption:launchoptions] to initialize the configuration content.    static NSString *channel = @ "Publish channel"; static BOOL isproduction = FALSE; #ifdef DEBUG isproduction = NO; #else isproduction = YES; #endif [Jpushservice setupwithoption:launchoptions appkey:@            "5B40040D828351E75003D2CB" Channel:channel apsforproduction:isproduction Advertisingidentifier:nil];} -(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions{//    Override point for customization after application launch.    Nsdictionary *userinfo = [Launchoptions Objectforkey:uiapplicationlaunchoptionsremotenotificationkey];        if (userInfo! = nil) {self.hasnotification = YES;        Self.notificationuserinfo = UserInfo;        if ([UserInfo objectforkey:@ "Update"]) {//[self Alertupdateapp];        }//nslog (@ "Launching userinfo:%@", userInfo);    [MessageBox showmsg:[[userinfo description] stringbyappendingstring:@ "launch"];    } [Smssdk Registerapp:smsappkey Withsecret:smsappsecret]; [Self SETUPREquestfilters];    Register Baidu Map _mapmanager = [[Bmkmapmanager alloc]init];    BOOL ret = [_mapmanager start:@ "Wcjptycmwpargmybaekohas8flzowavr" generaldelegate:self];    if (!ret) {NSLog (@ "manager start failed!");}    Self.locationcoordinate = Kcllocationcoordinate2dinvalid;    _locservice = [[Bmklocationservice alloc]init];    _locservice.delegate = self;        [_locservice Startuserlocationservice];        [Self basicsetup];        [Self initjpush:launchoptions]; return YES;}    -(void) Application: (UIApplication *) application didreceivelocalnotification: (uilocalnotification *) notification{    Application.applicationiconbadgenumber = 0; NSLog (@ "==left notifi:%@", [[UIApplication sharedapplication] scheduledlocalnotifications]);} -(void) Application: (UIApplication *) application didregisterusernotificationsettings: (Uiusernotificationsettings * ) notificationsettings{} #pragma mark-jpushregisterdelegate////IOS support//-(void) JpushnotificationcEnter: (Unusernotificationcenter *) center//willpresentnotification: (unnotification *) notification//WithCo Mpletionhandler: (void (^) (Nsinteger)) completionhandler//{////required////nsdictionary * userInfo = NOTIFICATION.R equest.content.userinfo;////if ([Notification.request.trigger Iskindofclass:[unpushnotificationtrigger class])// {////[Jpushservice handleremotenotification:userinfo];////}////Completionhandler (UNNotificationPrese Ntationoptionalert); Need to execute this method, choose whether to remind the user, there are badge, sound, alert three types can choose to set//}//////IOS support//-(void) Jpushnotificationcenter: ( Unusernotificationcenter *) center//didreceivenotificationresponse: (unnotificationresponse *) response//WithCompl Etionhandler: (void (^) ()) completionhandler//{////required////nsdictionary * userInfo = response.notification.requ est.content.userinfo;////if ([Response.notification.request.trigger Iskindofclass:[unpushnotificationtrigger Class]]) {////[JpushserviCe handleremotenotification:userinfo];////}////completionhandler ();    The system requires that this method be performed//}-(void) alertupdateapp{__weak typeof (self), ws = Self; Uialertcontroller *alert = [Uialertcontroller alertcontrollerwithtitle:@] The current app has a new version, is it updated now?                                                            "Message:nil    Preferredstyle:uialertcontrollerstylealert]; Uialertaction *ok = [uialertaction actionwithtitle:@ "OK" style:uialertacti                             Onstyledefault handler:^ (uialertaction *action) {                             Nsurl *url = [nsurl urlwithstring:[ws.notificationuserinfo objectforkey:@ "Update"];                         [[UIApplication sharedapplication] openurl:url];    }];                                               Uialertaction *cancel = [uialertaction actionwithtitle:@ "Cancel"      Style:uialertactionstyledefault handler:^ (uialertaction *action) {                                                   ;    }];    [Alert Addaction:ok];    [Alert Addaction:cancel];    Alert.view.backgroundColor = [Uicolor Whitecolor];    Uiviewcontroller *ROOTVC = [UIApplication sharedapplication].keywindow.rootviewcontroller;    Uiviewcontroller *TEMPVC;    while ((TEMPVC = Rootvc.presentedviewcontroller)) {ROOTVC = TEMPVC; } [ROOTVC Presentviewcontroller:alert Animated:yes completion:^{}];} -(void) Application: (UIApplication *) application didreceiveremotenotification: (nsdictionary *) userInfo Fetchcompletionhandler: (void (^) (uibackgroundfetchresult)) completionhandler{//Required, IOS 7 support [Jpushse    Rvice Handleremotenotification:userinfo];    Completionhandler (Uibackgroundfetchresultnewdata);   NSLog (@ "iOS7 and above system, receive notification:%@", [self logdic:userinfo]); Self.notificationuserinfo = UserInfo;    [MessageBox showmsg:[[userinfo description] stringbyappendingstring:@ "iOS7"];    if ([UserInfo objectforkey:@ "Update"]) {[Self alertupdateapp]; } else {[[Nsnotificationcenter Defaultcenter] postnotificationname:receiveremotenotification object:self use    Rinfo:userinfo]; }}-(void) Application: (UIApplication *) application didreceiveremotenotification: (nsdictionary *) userInfo{//Requir    Ed,for systems with less than or equal to iOS6 [Jpushservice Handleremotenotification:userinfo];    NSLog (@ "iOS6 and following systems, received notification:%@", [self logdic:userinfo]);    [MessageBox showmsg:[[userinfo description] stringbyappendingstring:@ "IOS6"];    Self.notificationuserinfo = UserInfo;    if ([UserInfo objectforkey:@ "Update"]) {[Self alertupdateapp]; } else {[[Nsnotificationcenter Defaultcenter] postnotificationname:receiveremotenotification object:self use    Rinfo:userinfo]; }}//log nsset with utf8//if noT, log would be \uxxx-(NSString *) Logdic: (Nsdictionary *) dic {if (![    DiC Count]) {return nil;                                                 } nsstring *tempstr1 = [[dic description] stringbyreplacingoccurrencesofstring:@ "\\u"    withstring:@ "\\u"];    NSString *TEMPSTR2 = [tempStr1 stringbyreplacingoccurrencesofstring:@ "\" "withstring:@" \\\ ""];    NSString *TEMPSTR3 = [[@ "\" "stringbyappendingstring:tempstr2] stringbyappendingstring:@" \ ""];    NSData *tempdata = [TempStr3 datausingencoding:nsutf8stringencoding]; NSString *str = [Nspropertylistserialization propertylistfromdata:tempdata Mutabili                                     Tyoption:nspropertylistimmutable Format:null    Errordescription:null]; return str;} -(void) Application: (UIApplication *) application Didregisterforremotenotificationswithdevicetoken: (NSData *) devicetoken{//Required-register Devicetoken [JpushserVice Registerdevicetoken:devicetoken]; [MessageBox showmsg:[devicetoken description];} -(void) Applicationwillresignactive: (uiapplication *) application {//Sent when the application was about to move from a Ctive to inactive state. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS message) or when the US    Er quits the application and it begins the transition to the background state. Use the This method to the pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should with this method to pause the game.} -(void) Applicationdidenterbackground: (uiapplication *) application {//Use the method to release shared resources, SA  ve user data, invalidate timers, and store enough application state information to restore your application    State-in-case it is terminated later. If your application supports background execution, this method is called instead of Applicationwillterminate:when the USer quits.} -(void) Applicationwillenterforeground: (uiapplication *) application {//called as part of the transition from the back Ground to the inactive state; Here's can undo many of the changes made on entering the background.} -(void) Applicationdidbecomeactive: (uiapplication *) application {//Restart any tasks this were paused (or not yet STA rted) While the application was inactive.    If the application is previously in the background, optionally refresh the user interface. Application.applicationiconbadgenumber = 0;} -(void) Applicationwillterminate: (uiapplication *) application {//called when the application was about to terminate. S Ave data if appropriate. See also Applicationdidenterbackground:.} #pragma mark-download backgroundsessionhandle--(void) Application: (UIApplication *) application    Handleeventsforbackgroundurlsession: (NSString *) identifier Completionhandler: (void (^) ()) completionhandler{ Self.backgroundsessioncompletionhandler = Completionhandler;} # pragma Mark-remote control-(void) basicsetup{//Remove control [[UIApplication sharedapplication] Beginreceivingremotec    Ontrolevents]; [Self becomefirstresponder];} -(BOOL) canbecomefirstresponder{return YES;    -(void) Remotecontrolreceivedwithevent: (uievent *) receivedevent{if (Receivedevent.type = = Uieventtyperemotecontrol) {switch (receivedevent.subtype) {case uieventsubtyperemotecontrolpause: [[Audi                Oplayercontroller Audioplayercontroller] stop];            Break                Case uieventsubtyperemotecontrolstop: [[Audioplayercontroller Audioplayercontroller] stop];            Break                Case Uieventsubtyperemotecontrolplay: [[Audioplayercontroller Audioplayercontroller] play];            Break Case Uieventsubtyperemotecontroltoggleplaypause: [[Audioplayercontroller Audioplayercontroller] PlayerStatu                S];            Break Case UieventsubtyperEmotecontrolnexttrack: [[Audioplayercontroller Audioplayercontroller] thenextsong];            Break                Case Uieventsubtyperemotecontrolprevioustrack: [[Audioplayercontroller Audioplayercontroller] inASong];            Break        Default:break; }}} @end

  

The app update prompt in remote notifications.

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.