ios--Local Notifications

Source: Internet
Author: User

    1. iOS8 send local notifications, you need to register local notifications first.
    2. if ([[uiapplication sharedapplication]currentusernotificationsettings]. Types= =Uiusernotificationtypenone) currently applied local notification type, uiusernotificationtypenone not registered local notification registration is System level, Not related to the program, when the program is removed after the reinstallation is still authorized, the ID is bound.

      Each time the authorization operation is performed, it will go this agent-(void) Application: (UIApplication *) application didregisterusernotificationsettings: ( Uiusernotificationsettings *) notificationsettings;
  1. Uiusernotificationtypenone = 0, //application must not present any user interface at the time of receiving the notification
  2. Uiusernotificationtypebadge = 1 << 0, //The application can mark its icon as
  3. Uiusernotificationtypesound = 1 << 1, //The app can make a sound after receiving a notification
  4. Uiusernotificationtypealert = 1 << 2, //The application can display alerts after notification is received
  5. (corresponding mark, sound, Banner)

The actual development is divided into two situations 1. When the application exits to the background, click Push to enter the program. This time can be by using-(void) Application: (UIApplication *) application didreceivelocalnotification: (Uilocalnotification *) notification; Gets the push information according to this method. 2. When the app is killed, the interface is reloaded when the push comes in. -(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions; You can get push content based on launchoptions. Receive notification parameters uilocalnotification *notification=[launchoptions Valueforkey: Uiapplicationlaunchoptionslocalnotificationkey];

  

-(void) addnotification{    uilocalnotification *notification=[[uilocalnotification alloc]init];    Notification.firedate=[nsdate Datewithtimeintervalsincenow:10];    [Email protected] "notice";    [[UIApplication sharedapplication]schedulelocalnotification:notification];}

  

Implement a small function: When the user does not operate for 1 hours in a row will be prompted by local push user action, every 1 hours prompt. -(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {//        Notification authorization if ([[UIApplication Sharedapplication]currentusernotificationsettings].types==uiusernotificationtypenone) { [[UIApplication sharedapplication] registerusernotificationsettings:[uiusernotificationsettings settingsForTypes: Uiusernotificationtypealert| uiusernotificationtypebadge|    Uiusernotificationtypesound Categories:nil]]; }}//lost Focus-(void) Applicationwillresignactive: (uiapplication *) application{[self addnotification];}    -(void) addnotification{uilocalnotification *notification=[[uilocalnotification Alloc]init];    Notification.firedate=[nsdate Datewithtimeintervalsincenow:10];    [email protected] "One minute no use"; notification.repeatinterval=nscalendarunitminute;//set the frequency of repetition [[UIApplication sharedapplication] Schedulelocalnotification:notification];} Clear all local notifications [[UIApplication sharedapplication]cancelalllocalNotifications]; 

  

ios--Local 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.