gpt4 book ai didi

ios - 推送通知在 IOS 11 中不起作用

转载 作者:行者123 更新时间:2023-11-30 12:01:36 26 4
gpt4 key购买 nike

您好,我正在尝试实现 google firebase 推送通知。

我使用的是 IOS 11Xcode 9.0

Pod 文件

target 'VQ Smart Home' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!

# Pods for VQ Smart Home
pod 'SwiftyJSON'
pod 'NVActivityIndicatorView'
pod 'FirebaseInstanceID', '2.0.0'
pod 'Firebase/Core'
pod 'Firebase/Messaging'
end

应用程序委托(delegate)

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

UINavigationBar.appearance().isTranslucent = true

/************************ FireBase Notification ************************************************************************/
FirebaseApp.configure()
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
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()

let token = Messaging.messaging().fcmToken
print("*********************************************************************************************************************")
print("FCM token: \(token ?? "")")
print("*********************************************************************************************************************")
/************************ FireBase Notification ************************************************************************/

return true
}

// Push Notification Methods
func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
print("Firebase registration token: \(fcmToken)")
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
print(userInfo)
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
print(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}

错误

*********************************************************************************************************************
FCM token: dEukPynDndQ:APA91bG41IAmwarrpdqoUmYxQQ_a6Ro-13YycSXTTyrqRHDGnroJ0pI2cSS5XYIQJwL50s07zUJcaujuj7SY-F5jO_bVEkVpFFyz4jylmwAlgief65Cpl6_TSgNNXkd-eDse7p1uk_rE
*********************************************************************************************************************
- [BoringSSL] Function boringssl_context_get_peer_sct_list: line 1754 received sct extension length is less than sct data length
- [MC] Lazy loading NSBundle MobileCoreServices.framework
- [MC] Loaded MobileCoreServices.framework
- [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
- refreshPreferences: HangTracerEnabled: 0
- refreshPreferences: HangTracerDuration: 500
- refreshPreferences: ActivationLoggingEnabled: 0 ActivationLoggingTaskedOffByDA:0
- [Firebase/Analytics][I-ACS023007] Firebase Analytics v.40004000 started
- [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (URL)
- TIC Read Status [1:0x0]: 1:57
- TIC Read Status [1:0x0]: 1:57

我已将正确的 APNs key 添加到 Firebase。并且仍然没有收到推送通知。有人可以帮我解决这个问题吗?交易。

最佳答案

找到解决办法

更新 podfile

pod 'Firebase/Core', '4.0.4'
pod 'Firebase/Database', '4.0.4'
pod 'Firebase/Messaging', '4.0.4'
pod 'FirebaseInstanceID', '2.0.0'

添加此方法didRegisterForRemoteNotificationsWithDeviceToken

应用程序委托(delegate)

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
}

现在尝试通过 firebase Ui 发送推送通知,您将在此方法中收到它 (didReceiveRemoteNotification)

 func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
print(userInfo)
let aps = userInfo["aps"] as! NSDictionary
print(aps["alert"] as? String ?? "")
completionHandler(UIBackgroundFetchResult.newData)
}

关于ios - 推送通知在 IOS 11 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47149238/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com