iOS 本地通知 操作

iOS 本地通知 操作

1:配置通知:然后退出程序;

iOS 本地通知 操作
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = date;  // date after 10 sec from now
localNotif.timeZone = [NSTimeZone defaultTimeZone];

// Notification details
localNotif.alertBody =  text; // text of you that you have fetched
// Set the action button
localNotif.alertAction = @"View";

localNotif.soundName = UILocalNotificationDefaultSoundName;
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];
iOS 本地通知 操作

2:接收通知,打开操作

iOS 本地通知 操作
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

// Override point for customization after application launch.

// Add the view controller‘s view to the window and display.
[window addSubview:viewController.view];
[window makeKeyAndVisible];

application.applicationIconBadgeNumber = 0;

// Handle launching from a notification
UILocalNotification *localNotif =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
    NSLog(@"Recieved Notification %@",localNotif);
}

return YES;
       }

  - (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification  *)notif {
// Handle the notificaton when the app is running
NSLog(@"Recieved Notification %@",notif);
       }
iOS 本地通知 操作

 

参考:http://*.com/questions/19357087/how-to-display-notifications-in-status-bar-using-dynamic-data-in-iphone

iOS 本地通知 操作

上一篇:iOS:ODRefreshControl


下一篇:设计模式之四:单例模式