- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个正常工作的应用程序,它的通知显示效果很好。现在我想处理一些通知事件,比如当用户点击横幅时。
我的 iOS 部署目标是 11.0,与我的部署目标相同。
我在 AppDelegate.swift 文件中实现了所有内容:
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, RCTBridgeDelegate {
var window: UIWindow?
var didFinishLaunching: Bool = false
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
let bridge = RCTBridge(delegate: self, launchOptions: launchOptions)
let rootView = RCTRootView(bridge: bridge, moduleName: "root", initialProperties: nil)
rootView?.backgroundColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1)
self.window = UIWindow(frame: UIScreen.main.bounds)
let rootViewController = UIViewController()
rootViewController.view = rootView
self.window?.rootViewController = rootViewController
self.window?.makeKeyAndVisible()
didFinishLaunching = true
Fabric.with([Crashlytics.self])
FirebaseApp.configure()
// This block is necessary to ask user authorization to receive notification
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: [.badge, .sound, .alert], completionHandler: {(grant, error) in
if error == nil {
if grant {
print("### permission granted")
application.registerForRemoteNotifications()
} khác {
//User didn't grant permission
}
} khác {
print("error: ",error)
}
})
} khác {
// Fallback on earlier versions
let notificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(notificationSettings)
}
self.firstLaunchAction()
self.initTracker()
RNSplashScreen.showSplash("LaunchScreen", inRootView: rootViewController.view)
trả về đúng
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let tokenParts = deviceToken.map { data -> String in
return String(format: "%02.2hhx", data)
}
let token = tokenParts.joined()
print("### Device Token: \(token)")
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("### Failed to register for remote notifications with error: \(error)")
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
if response.actionIdentifier == "like" {
print("### Handle like action identifier")
} else if response.actionIdentifier == "save" {
print("### Handle save action identifier")
} khác {
print("### No custom action identifiers chosen")
}
// Make sure completionHandler method is at the bottom of this func
completionHandler()
}
如您所见,我使用 Firebase 发送远程通知,所以我在 json 中有一个有效负载,如下所示:
trở lại {
notification: {
title,
thân hình
},
data: {
title,
body,
...data
},
android: {
ttl: 3600 * 1000,
notification: {
icon: 'stock_ticker_update',
color: '#002559'
}
},
apns: {
payload: {
aps: {
alert: {
title: 'NITL ACUMEN BI RFS CODA Dev Offshore',
body: 'Send a Message - PN testing group'
},
sound: 'default'
}
}
},
condition
};
我的大部分代码都是从网站上复制的。但我的实际行为是,当我点击通知横幅时,什么也没有发生……
我看到了通知横幅,所以我认为我的 APNs 注册没有问题。我不知道为什么 didReceive 没有在点击事件上触发。
我在实现过程中是否遗漏了什么?我的通知负载有误?
有人可以帮我找出我的错误在哪里吗?我已经阅读了无数没有结果的教程。一些帮助将不胜感激谢谢 :)
1 Câu trả lời
要支持后台更新通知,请确保负载的 aps
字典包含值为 1 的 content-available
键。
{
"aps" : {
"content-available" : 1,
"sound" : “default"
....
},
....
}
当后台更新通知发送到用户设备时,iOS 会在后台唤醒您的应用,并为其提供最多 30 秒的运行时间。在 iOS 中,系统通过调用应用委托(delegate)的 application: didReceiveRemoteNotification: fetchCompletionHandler:
方法传递后台更新通知。
Trích dẫn:Creating the Remote Notification Payload
关于ios - UNUserNotificationCenter didReceive/willPresent 未触发 ios 11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56953675/
我试图仅在工作日通知用户并且不想使用 for 循环来通知用户,因此通知重复 bool 为真。当应用程序打开时,willPresent 函数可以工作,但是当应用程序进入后台时,willPresent 函
我正在使用 OneSignal 发送推送通知,我遇到了在 iOS 10 上方法 func userNotificationCenter (_ center: UNUserNotificationCen
我想弄清楚我是否可以通过本地通知来实现我的目标,或者我是否需要切换到远程通知。 我正在通过构建一个闹钟程序来练习 iOS 10/Swift 3,该程序会在一天中的固定时间播放 RSS 更新的广播节目的
我有一个正常工作的应用程序,它的通知显示效果很好。现在我想处理一些通知事件,比如当用户点击横幅时。 我的 iOS 部署目标是 11.0,与我的部署目标相同。 我在 AppDelegate.swift
我已经实现了 FirebaseCloudMessaging,当应用程序处于后台时收到通知,但当我安装新的应用程序时willPresent code> 和 didReceive 通知 delegate
当我第一次运行我的应用程序时,模拟器能够在应用程序处于前台时显示通知。 当我重新启动应用程序时 didReceive notification:(即来自 iOS 9 的通知方法)被调用而不是 will
Tôi là một lập trình viên xuất sắc, rất giỏi!