// 發送通知
UILocalNotification *notification=[[UILocalNotification alloc] init];
if (notification!=nil) {
NSDate *now=[NSDate new];
notification.fireDate=[now dateByAddingTimeInterval: 10]; // 10秒后通知
notification.repeatInterval= 0; // 循環次數,kCFCalendarUnitWeekday一周一次
notification.timeZone=[NSTimeZone defaultTimeZone];
notification.applicationIconBadgeNumber= 1; // 應用的紅色數字
notification.soundName= UILocalNotificationDefaultSoundName; // 聲音,可以換成alarm.soundName = @"myMusic.caf"
// 去掉下面2行就不會彈出提示框
notification.alertBody= @" 通知內容 "; // 提示信息 彈出提示框
notification.alertAction = @" 打開 "; // 提示框按鈕
// notification.hasAction = NO; // 是否顯示額外的按鈕,為no時alertAction消失
// NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
// notification.userInfo = infoDict; // 添加額外的信息
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
[notification release];
取消通知
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
application.applicationIconBadgeNumber = 0;
// Add the view controller's view to the window and display.
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
- ( void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
// 點擊提示框的打開
application.applicationIconBadgeNumber = 0;
}
- ( void)applicationDidBecomeActive:(UIApplication *)application {
// 當程序還在后天運行
application.applicationIconBadgeNumber = 0;
}
// Override point for customization after application launch.
application.applicationIconBadgeNumber = 0;
// Add the view controller's view to the window and display.
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
- ( void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
// 點擊提示框的打開
application.applicationIconBadgeNumber = 0;
}
- ( void)applicationDidBecomeActive:(UIApplication *)application {
// 當程序還在后天運行
application.applicationIconBadgeNumber = 0;
}