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

iOS 本地推送實作

編輯:iOS 開發綜合

本地通知適合提醒、待辦或離線訊息。實作時可建立 UILocalNotification,並在前景收到通知時以彈窗呈現。

建立通知

設定 fireDate、alertBody、alertAction、soundName 與 userInfo,再呼叫 presentLocalNotificationNow。

UILocalNotification *notification = [[UILocalNotification alloc] init]; notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1]; notification.alertBody = @"提醒內容"; notification.soundName = @"sound.caf"; [application presentLocalNotificationNow:notification];

接收通知

在 didReceiveLocalNotification 中可建立 UIAlertController 顯示內容。若 App 在前景收到遠端通知,也可判斷 applicationState 後轉成本地提醒。

若專案支援較新 iOS,建議改用 UserNotifications 框架的 UNNotificationRequest。

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