我试图推送通知工作,但我的印象是方法" didRegisterForRemoteNotificationsWithDeviceToken"永远不会被调用," didFailToRegisterForRemoteNotificationsWithError"的情况相同。 stackoverflow上的一些旧线程显示完全相同的问题,但提供的解决方案对我没有用:/
我到处搜索过,似乎我遇到了这个问题,令牌从未打印到控制台,我得到的唯一输出是:
CREATE TABLE films (
code char(5) CONSTRAINT firstkey PRIMARY KEY,
title varchar(40) NOT NULL,
did integer NOT NULL,
date_prod date,
kind varchar(10),
len interval hour to minute
);
我做了什么:
这是我的代码(appdelegate.swift):
Permission granted: true
Notification settings: <UNNotificationSettings: 0x1c009cb10; authorizationStatus: Authorized, notificationCenterSetting: Enabled, soundSetting: Enabled, badgeSetting: Enabled, lockScreenSetting: Enabled, carPlaySetting: NotSupported, alertSetting: Enabled, alertStyle: Banner>
提前感谢!
答案 0 :(得分:0)
您实际上从未尝试注册推送通知,因此永远不会调用相关功能。您需要拨打func registerForPushNotifications() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
print("Permission granted: \(granted)")
guard granted else { return }
UNUserNotificationCenter.current().getNotificationSettings { (settings) in
print("Notification settings: \(settings)")
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
}
}
才能接收推送通知,而您当前的代码只会请求通知权限。
d8.jar