您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 程式開發 >> iOS 開發綜合

iOS 本地通知 UILocalNotification 使用流程

編輯:iOS 開發綜合

本地通知是 iOS 系統提供的提醒機制,常用於提醒、簽到或離開應用後的通知。

主要屬性

  • fireDate:觸發時間
  • timeZone:時區
  • repeatInterval:重複週期
  • alertBody:通知內容
  • soundName:提示音
  • applicationIconBadgeNumber:角標數字
  • userInfo:附帶參數

申請權限

[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil]];

建立通知

UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
notification.alertBody = @"這是一則本地通知";
notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];

取消與清理

[[UIApplication sharedApplication] cancelAllLocalNotifications];

若 App 回到前台,可將角標歸零;若需要傳遞參數,可從 userInfo 中取出。

  1. 上一篇文章:
  2. 下一篇文章:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © IOS教程網 All Rights Reserved