// 執(zhí)行通知一定要退出應(yīng)用或掛起應(yīng)用(進(jìn)入后臺(tái))才能收到通知。
// 創(chuàng)建本地通知
UILocalNotification *notification = [[UILocalNotification alloc] init];
// 通知觸發(fā)時(shí)間
// 5秒鐘之后觸發(fā)notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
// 通知時(shí)區(qū)
// 使用本地時(shí)區(qū)notification.timeZone = [NSTimeZone defaultTimeZone];
// 通知提示內(nèi)容
notification.alertBody = @"頂部提示內(nèi)容,您有有一個(gè)通知";
// 通知提示音
//使用默認(rèn)的通知提示音notification.soundName = UILocalNotificationDefaultSoundName;
// 應(yīng)用程序右上角顯示的數(shù)字
notification.applicationIconBadgeNumber = 1;
// 數(shù)據(jù)字典
notification.userInfo = @{@"userName": @"小明", @"age": @(18)};// 啟動(dòng)這個(gè)通知
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
// 進(jìn)入前臺(tái),清除右上角圖標(biāo)
- (void)applicationWillEnterForeground:(UIApplication *)application{ [application setApplicationIconBadgeNumber:0];}
// 點(diǎn)頂端通知進(jìn)入應(yīng)用
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"標(biāo)題" message:notification.userInfo[@"userName"] delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil]; [alert show];}
// 清除當(dāng)前應(yīng)用所有通知
[[UIApplication sharedApplication] cancelAllLocalNotifications];
|
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注