iOS development local notification (send a message on a daily basis)

Source: Internet
Author: User
Tags allkeys

NSDate now = [NSDate Date];
//Get system time
Nscalendar calendar = [[Nscalendar alloc] Initwithcalendaridentifier:nscalendaridentifiergregorian] ;
Nsdatecomponents *components = [[Nsdatecomponents alloc] init];
Nsinteger unitflags = Nscalendarunityear | Nscalendarunitmonth | Nscalendarunitday | Nscalendarunitweekday | Nscalendarunithour | Nscalendarunitminute | Nscalendarunitsecond;
Components = [Calendar components:unitflags Fromdate:now];
Nsinteger hour = [Components hour];
Nsinteger min = [Components minute];
Nsinteger sec = [Components second];
Nsinteger week = [Components weekday];
NSLog (@ "Now%ld:%ld:%ld, Week%ld", Hour,min,sec,week);

Uilocalnotification *localnotification = [[Uilocalnotification alloc] init];
Set the time zone (following the cell phone's time zone) Localnotification.timezone = [Nstimezone defaulttimezone];
    if (localnotification) {localnotification.alertbody = @ "message push message push";
    Localnotification.alertaction = @ "OPEN";
    Small icon Number Localnotification.applicationiconbadgenumber = 0;
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [Formatter setdateformat:@ "HH:mm:ss"];
    NSDate *date = [Formatter datefromstring:@ "15:30:00"];
The time Localnotification.firedate = Date of the notice issued;

}//cyclic notification cycle localnotification.repeatinterval = Kcfcalendarunitday;
Set UserInfo to facilitate the revocation of nsdictionary *info = [nsdictionary dictionarywithobject:@ "name" forkey:@ "Key"];
Localnotification.userinfo = info;
 Start task [[UIApplication sharedapplication] schedulelocalnotification:localnotification]; *////* for (uilocalnotification *obj in [uiapplication sharedapplication].scheduledlocalnotifications) {if ([Obj.userI Nfo.allkeys Containsobject:klocalnotIficationkey]) {[[UIApplication sharedapplication] cancellocalnotification:obj];
}//Set a local push at a fixed time nsdate *now = [NSDate Date];
Obtain system time Nscalendar *calendar = [[Nscalendar alloc] Initwithcalendaridentifier:nscalendaridentifiergregorian];
Nsdatecomponents *components = [[Nsdatecomponents alloc] init]; Nsinteger unitflags = Nscalendarunityear | Nscalendarunitmonth | Nscalendarunitday | Nscalendarunitweekday | Nscalendarunithour | Nscalendarunitminute |
Nscalendarunitsecond;
components = [Calendar components:unitflags Fromdate:now];
Nsinteger hour = [Components hour];
Nsinteger min = [Components minute];
Nsinteger sec = [Components second];
Nsinteger week = [Components weekday];

Wdlog (@ "Now is%ld:%ld:%ld, Zhou%ld", Hour,min,sec,week);
Uilocalnotification *localnotification = [[Uilocalnotification alloc] init];
Set the time zone (following the cell phone's time zone) Localnotification.timezone = [Nstimezone defaulttimezone];
    if (localnotification) {localnotification.alertbody = @ "message push message push"; LocalnotificatIon.alertaction = @ "OPEN";
    Small icon Number Localnotification.applicationiconbadgenumber = 0;
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [Formatter setdateformat:@ "HH:mm:ss"];
    NSDate *date = [Formatter datefromstring:@ "15:30:00"];
The time Localnotification.firedate = Date of the notice issued;

}//cyclic notification cycle localnotification.repeatinterval = Kcfcalendarunitday;
Set UserInfo to facilitate the revocation of nsdictionary *info = [nsdictionary dictionarywithobject:@ "name" forkey:@ "Key"];
Localnotification.userinfo = info;
 Start task [[UIApplication sharedapplication] schedulelocalnotification:localnotification]; *////* for (uilocalnotification *obj in [uiapplication sharedapplication].scheduledlocalnotifications) {if ([Obj.userI Nfo.allkeys Containsobject:klocalnotificationkey]) {[[UIApplication sharedapplication] CancelLocalNotification:ob
    J]; }///Cancel all local notifications directly//[[uiapplication Sharedapplication] cancelalllocalnotifications];
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.