我使用自己的服务器,使用FCM向ios设备推送通知,推送通知成功,我还使用Realm数据库系统帮我存储fcm推送通知,但是只有以下两种情况存储才会成功。情况1:当应用程序运行时。
情况2:当您点击推送横幅通知时,应用程序被杀死或在后台运行。
但这不是我的主要意图。我知道当应用程序被终止时,我无法处理推送通知,因此我希望能够在用户打开应用程序时存储推送通知。
抱歉,我的英语不好。如果有不清楚的地方,请告诉我。
境界级
class Order: Object {
@objc dynamic var id = UUID().uuidString
@objc dynamic var name = ""
@objc dynamic var amount = ""
@objc dynamic var createDate = Date()
override static func primaryKey() -> String? {
return "id"
}
let realm = try! Realm()
let order: Order = Order()
Run Code Online (Sandbox Code Playgroud)
AppDelegate.swift(当应用程序运行时存储 fcm 消息)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo //
print("userInfo: \(userInfo)")
guard
let aps …Run Code Online (Sandbox Code Playgroud)