Local Notification in IOS
Step 1
Design this
Step 2
add this code in "viewController.h"
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
IBOutlet UITextField *message;
}
@property (nonatomic, retain) UITextField *message;
-(IBAction) btnSet:(id) sender;
-(IBAction) btnCancelAll:(id) sender;
@end
Step 3
type this code in "viewController.m"
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize message;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(IBAction) btnSet:(id) sender
{
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
//---set the notification to go off in 10 seconds time---
localNotification.fireDate =
[[NSDate alloc] initWithTimeIntervalSinceNow:10];
//---the message to display for the alert---
localNotification.alertBody = message.text;
localNotification.applicationIconBadgeNumber = 1;
//---uses the default sound---
localNotification.soundName = UILocalNotificationDefaultSoundName;
//---title for the button to display---
localNotification.alertAction = @"View Details";
//---schedule the notification---
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[localNotification release];
}
-(IBAction) btnCancelAll:(id) sender
{
//---cancel all notifications---
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Step 4
add this method in "AppDelegate.m"
- (void) application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Inside application Receive Local Notification "
message:notification.alertBody
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
application.applicationIconBadgeNumber = 0;
[alert show];
[alert release];
}
Step 5
Step 6
Run Your app
Type Something |
After 10 Second |
Click the Notification |
Good Luck!
Tutorial List
- SQLite Based iPhone Application
- json with IOS (Basic) - Tutorial
- Simple Table View in IOS
- Load Distinct Images from array into UITableView
- Simple UIPickerView Example
- Tab Bar Application Part 1
- Tab Bar Application Part 2
- Tab Bar Application Part 3 ( with Login Screen )
- Tab Bar Application Part 4 ( Navigation )
- Table View Design in IOS Part 1
- Table View Design in IOS Part 2 ( Time Table )
- How to Add search bar in Table View
- Local Notification in IOS
- Core Data (For Beginners )
- Core Data Tute 2 (Add/Delete/Search)
- Core Data Tute 3 (Two table)
- Custom Cell in UITableview
- Lazy Loading
- Pull to Refresh in TableView
- Working with keyboard in Objective C - Part 1
No comments:
Post a Comment