IOS 在生产环境中没有收到推送通知
IOS not getting Push Notifications in production environment
我厌倦了寻找问题,上传到 App store 后,我在生产环境中没有收到推送通知。
我尝试了我在网上听到的所有可能的方法,但没有机会
我在 APNS 中收到以下错误:
10:06:09: 准备发送负载...
10:06:09:正在尝试连接....
10:06:09:已连接....
10:06:10:已发送并已断开连接......!
10:06:20:None(未知)
有时我得到(无效令牌)
推送通知在开发人员模式下运行良好,但在存档时根本无法运行。
另一方面,下面是我的 AppDelegate 代码:
var window: UIWindow?
var settings: UNNotificationSettings?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]) -> Bool {
// Override point for customization after application launch.
// iOS 10 support
FirebaseApp.configure()
if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
NotificationCenter.default.addObserver(self, selector: #selector(self.tokenRefreshNotification),
name: NSNotification.Name.InstanceIDTokenRefresh, object: nil)
return true
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
{
completionHandler([.alert, .badge, .sound])
}
func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
print("Firebase registration token: \(fcmToken)")
}
func 应用程序(应用程序:UIApplication,
didFailToRegisterForRemoteNotificationsWithError 错误:NSError){
打印(错误)
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
// Let FCM know about the message for analytics etc.
Messaging.messaging().appDidReceiveMessage(userInfo)
// Print message ID.
// Print full message.
print("userInfo: \(userInfo)")
completionHandler(.noData)
}
func registerForPushNotifications() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {
(granted, error) in
print("Permission granted: \(granted)")
guard granted else { return }
self.getNotificationSettings()
}
}
func getNotificationSettings() {
UNUserNotificationCenter.current().getNotificationSettings { (settings) in
print("Notification settings: \(settings)")
guard settings.authorizationStatus == .authorized else { return }
UIApplication.shared.registerForRemoteNotifications()
}
}
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask(rawValue: UIInterfaceOrientationMask.portrait.rawValue)
}
func tokenRefreshNotification(notification: NSNotification) {
if let refreshedToken = InstanceID.instanceID().token() {
print("InstanceID token: \(refreshedToken)")
// Subscribe to a topic after got a FCM Registration token
Messaging.messaging().subscribe(toTopic: "/topics/coffee")
}
// Connect to FCM since connection may have failed when attempted before having a token.
connectToFCM()
}
// [END refresh_token]
// [START connect_to_fcm]
func connectToFCM() {
Messaging.messaging().connect { (error) in
if (error != nil) {
print("Unable to connect with FCM. \(error)")
} else {
print("Connected to FCM.")
}
}
}
// [END connect_to_fcm]
func applicationDidBecomeActive(application: UIApplication) {
connectToFCM()
}
// [START disconnect_from_fcm]
func applicationDidEnterBackground(application: UIApplication) {
Messaging.messaging().disconnect()
print("Disconnected from FCM.")
}
}
您需要检查 PHP 端的推送 notification.Production 环境 您无法在您这边检查推送通知,您需要从服务器触发边-
开发服务器-
ssl://gateway.sandbox.push.apple.com:2195
生产服务器 -
ssl://gateway.push.apple.com:2195
如果您遇到任何端口问题,您可以尝试使用 -
- 2195
- 2196
更多详情- Check this link
我厌倦了寻找问题,上传到 App store 后,我在生产环境中没有收到推送通知。 我尝试了我在网上听到的所有可能的方法,但没有机会 我在 APNS 中收到以下错误:
10:06:09: 准备发送负载... 10:06:09:正在尝试连接.... 10:06:09:已连接.... 10:06:10:已发送并已断开连接......! 10:06:20:None(未知) 有时我得到(无效令牌)
推送通知在开发人员模式下运行良好,但在存档时根本无法运行。
另一方面,下面是我的 AppDelegate 代码:
var window: UIWindow?
var settings: UNNotificationSettings?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]) -> Bool {
// Override point for customization after application launch.
// iOS 10 support
FirebaseApp.configure()
if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
NotificationCenter.default.addObserver(self, selector: #selector(self.tokenRefreshNotification),
name: NSNotification.Name.InstanceIDTokenRefresh, object: nil)
return true
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
{
completionHandler([.alert, .badge, .sound])
}
func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
print("Firebase registration token: \(fcmToken)")
}
func 应用程序(应用程序:UIApplication, didFailToRegisterForRemoteNotificationsWithError 错误:NSError){ 打印(错误) }
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
// Let FCM know about the message for analytics etc.
Messaging.messaging().appDidReceiveMessage(userInfo)
// Print message ID.
// Print full message.
print("userInfo: \(userInfo)")
completionHandler(.noData)
}
func registerForPushNotifications() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {
(granted, error) in
print("Permission granted: \(granted)")
guard granted else { return }
self.getNotificationSettings()
}
}
func getNotificationSettings() {
UNUserNotificationCenter.current().getNotificationSettings { (settings) in
print("Notification settings: \(settings)")
guard settings.authorizationStatus == .authorized else { return }
UIApplication.shared.registerForRemoteNotifications()
}
}
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask(rawValue: UIInterfaceOrientationMask.portrait.rawValue)
}
func tokenRefreshNotification(notification: NSNotification) {
if let refreshedToken = InstanceID.instanceID().token() {
print("InstanceID token: \(refreshedToken)")
// Subscribe to a topic after got a FCM Registration token
Messaging.messaging().subscribe(toTopic: "/topics/coffee")
}
// Connect to FCM since connection may have failed when attempted before having a token.
connectToFCM()
}
// [END refresh_token]
// [START connect_to_fcm]
func connectToFCM() {
Messaging.messaging().connect { (error) in
if (error != nil) {
print("Unable to connect with FCM. \(error)")
} else {
print("Connected to FCM.")
}
}
}
// [END connect_to_fcm]
func applicationDidBecomeActive(application: UIApplication) {
connectToFCM()
}
// [START disconnect_from_fcm]
func applicationDidEnterBackground(application: UIApplication) {
Messaging.messaging().disconnect()
print("Disconnected from FCM.")
}
}
您需要检查 PHP 端的推送 notification.Production 环境 您无法在您这边检查推送通知,您需要从服务器触发边-
开发服务器-
ssl://gateway.sandbox.push.apple.com:2195
生产服务器 -
ssl://gateway.push.apple.com:2195
如果您遇到任何端口问题,您可以尝试使用 -
- 2195
- 2196
更多详情- Check this link