Local notifications for iOS

Source: Internet
Author: User
Tags date1
Local notifications for iOS

Local notifications are notifications Based on Time behaviors, such as small applications related to calendar or todo lists. In addition, if the app is executed in the background, IOS allows it to run within a limited period of time, and it will also find local notifications useful. For example, an application runs in the background and obtains a message from the application server. When a message arrives, for example, a prompt message for downloading an updated version, a local notification mechanism is used to notify the user.

Local notification is an instance of uilocalnotification, which has three attributes:

  • Scheduled time, a time period, used to specify the date and time when the IOS system sends notifications;
  • Notification Type, notification type, including warning information, action button title, Badge (digital flag) on the app icon, and playing sound;
  • Custom Data. Local notifications can contain local data of the dictionary type.

The maximum number of local notifications allowed by IOS is 64. Local notifications that exceed the limit will be ignored by IOS.

It is very easy to write a simple scheduled reminder, for example:


 

Uilocalnotification * localnotif = [[uilocalnotification alloc] init];

If (localnotif = nil)

Return;

// Localnotif. firedate = itemdate;

// Nsdate * Now = [nsdate new];

Nsdate * date1 = [nsdate datewithtimeinterval: 8 sincedate: date];

Localnotif. firedate = date1;

Nslog (@ "Now = % @", date1 );

Localnotif. timezone = [nstimezone defaulttimezone];

// Notification Details

Localnotif. alertbody = @ "it's time to eat, notification
........ ";

// Set the action button

Localnotif. alertaction = @ "View ";

Localnotif. soundname = uilocalnotificationdefasoundname;

Localnotif. applicationiconbadgenumber = 1;

// Specify custom data for the notification

Nsdictionary * infodict = [nsdictionary dictionarywithobject: @ "somevalue" forkey: @ "somekey"];

Localnotif. userinfo = infodict;

// Schedule the notification

[[Uiapplication sharedapplication] schedulelocalnotification: localnotif];

[Localnotif release];

// Nsarray * array = [[uiapplication sharedapplication] scheduledlocalconfigurications];

// [[Uiapplication sharedapplication] cancelalllocalconfigurications];

// [[Uiapplication sharedapplication] cancellocalnotification: localnotif];


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.