iOS local push implementation, compatible with IOS8

Source: Internet
Author: User

Code in the APPDELEGATE.M

APPDELEGATE.M-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (NSDictionary *) launchoptions {    //handling IOS8 Local push cannot receive the problem    float sysversion=[[uidevice currentdevice]systemversion].floatvalue;    if (sysversion>=8.0) {        Uiusernotificationtype Type=uiusernotificationtypebadge | Uiusernotificationtypealert | Uiusernotificationtypesound;        Uiusernotificationsettings *setting=[uiusernotificationsettings Settingsfortypes:type Categories:nil];        [[UIApplication sharedapplication]registerusernotificationsettings:setting];    }    return YES;}

Receive local push (added in APPDELEGATE.M)-(void) Application: (UIApplication *) application didreceivelocalnotification: ( Uilocalnotification *) notification{    Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "title" Message: Notification.alertbody delegate:nil cancelbuttontitle:@ "OK" otherbuttontitles:nil];    [Alert show];        The number on the icon is reduced by 1    application.applicationiconbadgenumber-= 1;}


-(void) Applicationwillenterforeground: (uiapplication *) application {    //when opening the app directly, the number on the icon is clear 0    Application.applicationiconbadgenumber = 0;}


Code that is added in the calling class

Push method//Set local push parameters and push-(void) schedulenotification{uilocalnotification *notification = [[Uilocalnotification All    OC] init];    Set 5 seconds after nsdate *pushdate = [NSDate datewithtimeintervalsincenow:5];        if (notification! = nil) {//Set push time (after 5 seconds) notification.firedate = pushdate;        Set the time zone (this is the default time zone) Notification.timezone = [Nstimezone defaulttimezone];        Set repeat interval (default 0, no repeat push) Notification.repeatinterval = 0;        Push sound (system default) Notification.soundname = Uilocalnotificationdefaultsoundname;        Push content Notification.alertbody = @ "Push main content";        The number shown on the icon Notification.applicationiconbadgenumber = 1;        Setting the UserInfo is convenient to use nsdictionary *info = [nsdictionary dictionarywithobject:@ "name" forkey:@ "key" when you need to revoke it later];        Notification.userinfo = info;        Add push to uiapplication uiapplication *app = [UIApplication sharedapplication];    [App Schedulelocalnotification:notification]; }}


iOS local push implementation, compatible with IOS8

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.