IOS client local push implementation code _ios

Source: Internet
Author: User

This example for you to share the iOS local push the specific code, for your reference, the specific content as follows

Create a global local notification object and pop-up box first

Pop-up local message @property (Nonatomic,strong) uilocalnotification *localnotification;

@property (Nonatomic,strong) Uialertcontroller *alertcontrol;
Second, the code is implemented as follows:-(void) Application: (UIApplication *) application didreceiveremotenotification: (nsdictionary *) userInfo Fetchcompletionhandler: (void (^) (uibackgroundfetchresult)) Completionhandler {//Determine if the program is open, that is, whether the status is running in the foreground (Applica Tion.applicationstate = = uiapplicationstateactive) {//If the message was previously accepted and the user did not process the pop-up box, close the original pop-up if (Self.localnotificati
    ON) {[Self.alertcontrol dismissviewcontrolleranimated:yes completion:nil];
    
    
  [Self bulidlocationnotification:application userinfo:userinfo]; }else{//Judge whether the program is not open, that is, whether it is running or shutting down in the background, Aurora push set the corner sign if ([application applicationiconbadgenumber]>0) {[Jpushserv
    Ice setbadge:[application Applicationiconbadgenumber]];
  } [Jpushservice Handleremotenotification:userinfo];
  NSLog (@ "received notice:%@", [self logdic:userinfo]); Completionhandler (uibackgroundfetchresultnewdATA);
  }-(void) Application: (UIApplication *) application didreceivelocalnotification: (uilocalnotification *) Notification { Pop-up message if (self.localnotification) {Self.alertcontrol = [Uialertcontroller alertcontrollerwithtitle:@ "" Message:se
    Lf.localNotification.alertBody Preferredstyle:uialertcontrollerstylealert]; Uialertaction *action = [uialertaction actionwithtitle:@ "OK" style:uialertactionstyledefault handler:^ (UIAlertAction
      * _nonnull action) {self.localnotification = nil;
    Self.alertcontrol = nil;
    }];
    [Self.alertcontrol addaction:action];
    
  [Self.window.rootViewController PresentViewController:self.alertcontrol Animated:yes Completion:nil]; }//Create local push message-(void) Bulidlocationnotification: (uiapplication *) application userinfo: (nsdictionary *) userinfo{self.
  Localnotification = [[Uilocalnotification alloc]init];
  Self.localNotification.fireDate = [NSDate datewithtimeintervalsincenow:1]; Self.localNotification.alertBody = [[UserInfo objectforkey:@ "APS"] objectforkey:@ "alert"];
  Self.localNotification.alertAction = @ "OK";
  Self.localNotification.soundName = @ "SOUND.CAF";
  Self.localNotification.userInfo = UserInfo;
[Application presentLocalNotificationNow:self.localNotification];
 }

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.