IOS Uilocalnotification timed Reminders

Source: Internet
Author: User

in iOS, there are two kinds of information prompt push method, one kind is remote server push (APNS) , there is a kind of local notice uilocalnotification, today to briefly record the use of uilocalnotification, the details are as follows:

Uilocalnotification *notifity=[[uilocalnotification alloc] init];        NSDateFormatter *formattr=[[nsdateformatter alloc] init];
Format Time [formattr setdateformat:@ "hh:mm"]; Trigger notification time nsdate *now=[formattr datefromstring:[nsstring stringwithformat:@ "%@", Strtimer]]; Notifity.firedate=now; Time zone notifity.timezone=[nstimezone Defaulttimezone]; The unit that notifies the repeating prompt, which can be weeks (nsweekdaycalendarunit) minutes (nsminutecalendarunit) seconds (nssecondcalendarunit) months (nsmonthcalendarunit) years ( Nsyearcalendarunit)

Notifity.repeatinterval=nsdaycalendarunit;
        Notification content        [email protected] "This is a notice";        The sound notifity.soundname=uilocalnotificationdefaultsoundname to be played when the notification is triggered        ;        Perform notification registration        [[uiapplication sharedapplication] schedulelocalnotification:notifity];

If you want to carry parameter information in the notification bar, you can use the following method:

   Nsdictionary *dic = [nsdictionary dictionarywithobject:@ "name" forkey:@ "key "];       = dic;

If the software is running, you can get and process the parameter information through the callback method in Appdelegate:

-(void) Application: (UIApplication *) application didreceivelocalnotification: (uilocalnotification *) notification{    if (notification) {        nsdictionary *userinfo =  notification.userinfo;        NSString *obj = [userInfo objectforkey:@ "key"];        NSLog (@ "%@", obj);}    }

In addition, there are two ways to unregister a local notification, one is to cancel the specified notification, and the second is to cancel all registration notifications:

[[UIApplication sharedapplication] cancellocalnotification:localnotification]; [[UIApplication sharedapplication] cancelalllocalnotification];

The above is what I learned today, recorded here and shared with you, if you have any questions, please point out the joint study!

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.