iOS local push-alert feature

Source: Internet
Author: User

creates a local message when the user leaves the application.
if the user needs to set some configuration information when using the application, use the class message with caution.

Suppose an application runs in the foreground. When the app switches from the home button to the background, 1 seconds later, you can see the popup information (iOS 5 and iOS 4 devices).





If the user taps this message, the application can be restored to the foreground.

The implementation code is very simple, create a NSDate object at the beginning, record the current date and time, add 1 seconds on this object,
sets the trigger time for local messages. Set up local notification messages and packages, and schedule notifications with the operating system.

Add the following code to the DELEGATE.M file:
-(void) Applicationdidenterbackground: (uiapplication *) application
{
  uilocalnotification *localnotification = [[[[Uilocalnotification alloc] init] autorelease];

  //Current date
  nsdate *date = [NSDate date]; 

  //Add One Second to the current time
  nsdate *datetofire = [date datebyaddingtimeinterval:1];

  //Set The fire date/time
  [localnotification Setfiredate:datetofire];
  [localnotification settimezone:[nstimezone defaulttimezone]];    

  / /SETUP Alert notification
  [localnotification setalertbody:@ "tap to return to TestApp"];
  [localnotification setalertaction:@ "Open TestApp"];
  [localnotification Sethasaction:yes];
  [[uiapplication sharedapplication] schedulelocalnotification:localnotification];
}


when the message box pops up, after the user clicks, the following method can be executed once the application is restored to the foreground
-(void) Application: (UIApplication *) application didreceivelocalnotification: (Uilocalnotification *) Notification
{
Your code here ...
}

iOS local push-alert feature

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.