iOS上的Unity Firebase Messaging:未调用OnTokenReceived

时间:2018-12-11 11:02:29

标签: ios firebase unity3d firebase-cloud-messaging

在Unity上使用Firebase Messaging有点麻烦,其中onTokenReceived似乎从未被调用。这是我所拥有的和所做的:

  • Unity 5.6.3f1
  • 用于Unity 5.4.2的Firebase,已将PlayServicesResolver设置为生成.xcworkspace导入
  • 在iOS上定义为CustomUnityAppController
  • IMPL_APP_CONTROLLER_SUBCLASS。在此类中,didRegisterForRemoteNotificationsWithDeviceTokensuper覆盖了。
  • 用于Firebase消息传递初始化的C#代码,如下所示:

    FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(OnInited);
    

OnInited:

_FirebaseApp = FirebaseApp.Create();
Firebase.Messaging.FirebaseMessaging.TokenRegistrationOnInitEnabled = false;
Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
Firebase.Messaging.FirebaseMessaging.RequestPermissionAsync().ContinueWith(()=>{bool result=FirebaseUtility.LogTask(task, "RequestPermissionAsync");});

现在,我确实看到使用设备令牌调用了覆盖的didRegisterForRemoteNotificationsWithDeviceToken,并且RequestPermissionAsync已完成。但是C#中的OnTokenReceived似乎从未被调用过。 我尝试注释掉IMPL_APP_CONTROLLER_SUBCLASS,从而使UnityAppController处理所有事件,但仍未触发回调。有任何帮助或建议吗?

下面的iOS调试日志:

2018-12-11 17:59:40.222959+0800 firebasedemo[583:68296] FCM: Loading UIApplication FIRFCM category
2018-12-11 17:59:40.279642+0800 firebasedemo[583:68321]  - <AppMeasurement>[I-ACS036002] Analytics screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable screen reporting, set the flag FirebaseScreenReportingEnabled to NO (boolean) in the Info.plist
2018-12-11 17:59:40.367276+0800 firebasedemo[583:68296] -> registered mono modules 0x1065b9720
2018-12-11 17:59:40.398001+0800 firebasedemo[583:68296] You've implemented -[<UIApplicationDelegate> application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add "remote-notification" to the list of your supported UIBackgroundModes in your Info.plist.
2018-12-11 17:59:40.402219+0800 firebasedemo[583:68296] Setting up iOS 10 message delegate.
-> applicationDidFinishLaunching()
2018-12-11 17:59:40.424125+0800 firebasedemo[583:68296] Player data archive not found at `/var/containers/Bundle/Application/E8C043D2-63BE-4BFD-9AB5-AE3EC1032BCA/firebasedemo.app/Data/data.unity3d`, using local filesystem
Player data archive not found at `/var/containers/Bundle/Application/E8C043D2-63BE-4BFD-9AB5-AE3EC1032BCA/firebasedemo.app/Data/data.unity3d`, using local filesystem-> applicationDidBecomeActive()
2018-12-11 17:59:40.532602+0800 firebasedemo[583:68339]  - <AppMeasurement>[I-ACS025026] Deferring to Firebase for event data collection
2018-12-11 17:59:40.557323+0800 firebasedemo[583:68296] GfxDevice: creating device client; threaded=1
GfxDevice: creating device client; threaded=1
2018-12-11 17:59:40.559058+0800 firebasedemo[583:68296] Initializing Metal device caps: Apple A9 GPU
Initializing Metal device caps: Apple A9 GPU
2018-12-11 17:59:40.561320+0800 firebasedemo[583:68296] Initialize engine version: 5.6.3f1 (d3101c3b8468)
Initialize engine version: 5.6.3f1 (d3101c3b8468)
2018-12-11 17:59:41.241134+0800 firebasedemo[583:68338] TIC SSL Trust Error [1:0x28072a1c0]: 3:0
2018-12-11 17:59:41.242527+0800 firebasedemo[583:68338] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9814)
2018-12-11 17:59:41.242605+0800 firebasedemo[583:68338] Task <B9A9E236-CB57-42F5-9CC8-0AC5AA558B48>.<0> HTTP load failed (error code: -1202 [3:-9814])
2018-12-11 17:59:41.243205+0800 firebasedemo[583:68340] NSURLConnection finished with error - code -1202
2018-12-11 17:59:41.728940+0800 firebasedemo[583:68361] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C2.1:4][0x139d56710] get output frames failed, state 8196
2018-12-11 17:59:41.729409+0800 firebasedemo[583:68361] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C2.1:4][0x139d56710] get output frames failed, state 8196
2018-12-11 17:59:41.729731+0800 firebasedemo[583:68361] TIC Read Status [2:0x0]: 1:57
2018-12-11 17:59:41.729765+0800 firebasedemo[583:68361] TIC Read Status [2:0x0]: 1:57
2018-12-11 17:59:42.855183+0800 firebasedemo[583:68296] UnloadTime: 0.507166 ms
UnloadTime: 0.507166 ms
2018-12-11 17:59:42.904570+0800 firebasedemo[583:68432] Setting up 1 worker threads for Enlighten.
Setting up 1 worker threads for Enlighten.
2018-12-11 17:59:42.907988+0800 firebasedemo[583:68433]   Thread -> id: 16c3b7000 -> priority: 1 
  Thread -> id: 16c3b7000 -> priority: 1 
2018-12-11 18:00:00.960575+0800 firebasedemo[583:68544] @FirebaseUtility.LogTask CheckAndFixDependenciesAsync: completed
2018-12-11 18:00:01.085425+0800 firebasedemo[583:68544] DEBUG: Creating firebase::App for Firebase C++ 5.4.2
2018-12-11 18:00:01.091475+0800 firebasedemo[583:68339] 5.12.0 - [Firebase/Messaging][I-FCM001000] FIRMessaging Remote Notifications proxy enabled, will swizzle remote notification receiver handlers. If you'd prefer to manually integrate Firebase Messaging, add "FirebaseAppDelegateProxyEnabled" to your Info.plist, and set it to NO. Follow the instructions at:
https://firebase.google.com/docs/cloud-messaging/ios/client#method_swizzling_in_firebase_messaging
to ensure proper integration.
2018-12-11 18:00:01.093285+0800 firebasedemo[583:68362] 5.12.0 - [Firebase/Analytics][I-ACS023007] Analytics v.50300000 started
2018-12-11 18:00:01.093347+0800 firebasedemo[583:68362] 5.12.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see <GOOGLE_URL>)
2018-12-11 18:00:01.096194+0800 firebasedemo[583:68544] Creating firebase::App for Firebase C++ 5.4.2
Firebase.FirebaseApp:CreateInternal()
Firebase.FirebaseApp:CreateAndTrack(CreateDelegate, FirebaseApp)
GCommon.FFFirebase.FirebaseUtility:InitApp()
GCommon.FFFirebase.FirebaseUtility:OnInited(Task`1)
System.Threading.Tasks.<ContinueWith>c__AnonStorey0:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey2:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey1:<>m__0()
System.Threading.Tasks.Task:<immediateExecutor>m__1(Action)
System.Threading.Tasks.Task`1:RunContinuations()
System.Threading.Tasks.Task`1:TrySetResult(T)
System.Threading.Tasks.<Unwrap>c__AnonStorey1`1:<>m__1(Task`1)
System.Threading.Tasks.<ContinueWith>c__AnonStorey0:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey2:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey1:<>m__0()
System.Threading.Tasks.Task:<immediateExecutor>m__1(Action)
System.Threading.Tasks.Task:ContinueWith(Func`2, CancellationToken)
System.Threading.Tasks.<ContinueWith>c__AnonStore
Creating firebase::App for Firebase C++ 5.4.2
Firebase.FirebaseApp:CreateInternal()
Firebase.FirebaseApp:CreateAndTrack(CreateDelegate, FirebaseApp)
GCommon.FFFirebase.FirebaseUtility:InitApp()
GCommon.FFFirebase.FirebaseUtility:OnInited(Task`1)
System.Threading.Tasks.<ContinueWith>c__AnonStorey0:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey2:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey1:<>m__0()
System.Threading.Tasks.Task:<immediateExecutor>m__1(Action)
System.Threading.Tasks.Task`1:RunContinuations()
System.Threading.Tasks.Task`1:TrySetResult(T)
System.Threading.Tasks.<Unwrap>c__AnonStorey1`1:<>m__1(Task`1)
System.Threading.Tasks.<ContinueWith>c__AnonStorey0:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey2:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey1:<>m__0()
System.Threading.Tasks.Task:<immediateExecutor>m__1(Action)
System.Threading.Tasks.Task:ContinueWith(Func`2, CancellationToken)
System.Threading.Tasks.<ContinueWith>c__AnonStorey0:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey2:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey1:<>m__0()
System.Threading.Tasks.Task:<immediateExecutor>m__1(Action)
System.Threading.Tasks.Task`1:RunContinuations()
System.Threading.Tasks.Task`1:TrySetResult(T)
System.Threading.Tasks.<ContinueWith>c__AnonStorey1:<>m__0()
System.Threading.Tasks.Task:<immediateExecutor>m__1(Action)
System.Threading.Tasks.Task`1:RunContinuations()
System.Threading.Tasks.Task`1:TrySetResult(T)
System.Threading.Tasks.TaskCompletionSource`1:SetResult(T)
System.Threading.Tasks.<StartNew>c__AnonStorey0`1:<>m__0()
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
2018-12-11 18:00:01.097126+0800 firebasedemo[583:68544] DEBUG: Added app name=__FIRAPP_DEFAULT: options, api_key=<API_KEY>, app_id=1:<APP_ID>:ios:<IOS_APP_ID>, database_url=https://<DEMO_ID>.firebaseio.com, messaging_sender_id=<APP_ID>, storage_bucket=<DEMO_ID>.appspot.com, project_id=<DEMO_ID> (0x3bb8bd00)
2018-12-11 18:00:01.097882+0800 firebasedemo[583:68544] Added app name=__FIRAPP_DEFAULT: options, api_key=<API_KEY>, app_id=1:<APP_ID>:ios:<IOS_APP_ID>, database_url=https://<DEMO_ID>.firebaseio.com, messaging_sender_id=<APP_ID>, storage_bucket=<DEMO_ID>.appspot.com, project_id=<DEMO_ID> (0x3bb8bd00)
Firebase.FirebaseApp:CreateInternal()
Firebase.FirebaseApp:CreateAndTrack(CreateDelegate, FirebaseApp)
GCommon.FFFirebase.FirebaseUtility:InitApp()
GCommon.FFFirebase.FirebaseUtility:OnInited(Task`1)
System.Threading.Tasks.<ContinueWith>c__AnonStorey0:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey2:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey1:<>m__0()
System.Threading.Tasks.Task:<immediateExecutor>m__1(Action)
System.Threading.Tasks.Task`1:RunContinuations()
System.Threading.Tasks.Task`1:TrySetResult(T)
System.Threading.Tasks.<Unwrap>c__AnonStorey1`1:<>m__1(Task`1)
System.Threading.Tasks.<ContinueWith>c__AnonStorey0:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__Ano
Added app name=__FIRAPP_DEFAULT: options, api_key=<API_KEY>, app_id=1:<APP_ID>:ios:<IOS_APP_ID>, database_url=https://<DEMO_ID>.firebaseio.com, messaging_sender_id=<APP_ID>, storage_bucket=<DEMO_ID>.appspot.com, project_id=<DEMO_ID> (0x3bb8bd00)
Firebase.FirebaseApp:CreateInternal()
Firebase.FirebaseApp:CreateAndTrack(CreateDelegate, FirebaseApp)
GCommon.FFFirebase.FirebaseUtility:InitApp()
GCommon.FFFirebase.FirebaseUtility:OnInited(Task`1)
System.Threading.Tasks.<ContinueWith>c__AnonStorey0:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey2:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey1:<>m__0()
System.Threading.Tasks.Task:<immediateExecutor>m__1(Action)
System.Threading.Tasks.Task`1:RunContinuations()
System.Threading.Tasks.Task`1:TrySetResult(T)
System.Threading.Tasks.<Unwrap>c__AnonStorey1`1:<>m__1(Task`1)
System.Threading.Tasks.<ContinueWith>c__AnonStorey0:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey2:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey1:<>m__0()
System.Threading.Tasks.Task:<immediateExecutor>m__1(Action)
System.Threading.Tasks.Task:ContinueWith(Func`2, CancellationToken)
System.Threading.Tasks.<ContinueWith>c__AnonStorey0:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey2:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey1:<>m__0()
System.Threading.Tasks.Task:<immediateExecutor>m__1(Action)
System.Threading.Tasks.Task`1:RunContinuations()
System.Threading.Tasks.Task`1:TrySetResult(T)
System.Threading.Tasks.<ContinueWith>c__AnonStorey1:<>m__0()
System.Threading.Tasks.Task:<immediateExecutor>m__1(Action)
System.Threading.Tasks.Task`1:RunContinuations()
System.Threading.Tasks.Task`1:TrySetResult(T)
System.Threading.Tasks.TaskCompletionSource`1:SetResult(T)
System.Threading.Tasks.<StartNew>c__AnonStorey0`1:<>m__0()
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
2018-12-11 18:00:01.142046+0800 firebasedemo[583:68544] @FirebaseUtility.InitModules() Analytics.Enabled: True
2018-12-11 18:00:01.143811+0800 firebasedemo[583:68544] @FirebaseUtility.InitModules() CloudMessaging.Enabled: True
2018-12-11 18:00:01.144386+0800 firebasedemo[583:68296] FCM: Initialize Firebase Messaging
2018-12-11 18:00:01.144543+0800 firebasedemo[583:68296] FCM: Initialize Firebase Messaging
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
FCM: Initialize Firebase Messaging
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
2018-12-11 18:00:01.144608+0800 firebasedemo[583:68296] FCM: Using FCM senderID <APP_ID>
2018-12-11 18:00:01.144684+0800 firebasedemo[583:68296] FCM: Using FCM senderID <APP_ID>
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
FCM: Using FCM senderID <APP_ID>
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
2018-12-11 18:00:01.149062+0800 firebasedemo[583:68544] ERROR: Status is pending. Return the pending future.
2018-12-11 18:00:01.150326+0800 firebasedemo[583:68544] Status is pending. Return the pending future.
Firebase.Messaging.FirebaseMessaging:RequestPermissionAsync()
GCommon.FFFirebase.CloudMessaging.CloudMessagingManager:RequestPermissionAsync(Action)
GCommon.FFFirebase.FirebaseUtility:InitModules()
System.Threading.Tasks.<ContinueWith>c__AnonStorey0:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey2:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey1:<>m__0()
System.Threading.Tasks.Task:<immediateExecutor>m__1(Action)
System.Threading.Tasks.Task`1:RunContinuations()
System.Threading.Tasks.Task`1:TrySetResult(T)
System.Threading.Tasks.<Unwrap>c__AnonStorey1`1:<>m__1(Task`1)
System.Threading.Tasks.<ContinueWith>c__AnonStorey0:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey2:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey1:<>m__0()
System.Threading.Tasks.Task:<immediateExecutor>m__1(Action)
System.Threading.Tasks.Task:ContinueWith(Func`2, CancellationToken)
System.Threading.Tasks.<ContinueWith>c__AnonStorey0
Status is pending. Return the pending future.
Firebase.Messaging.FirebaseMessaging:RequestPermissionAsync()
GCommon.FFFirebase.CloudMessaging.CloudMessagingManager:RequestPermissionAsync(Action)
GCommon.FFFirebase.FirebaseUtility:InitModules()
System.Threading.Tasks.<ContinueWith>c__AnonStorey0:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey2:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey1:<>m__0()
System.Threading.Tasks.Task:<immediateExecutor>m__1(Action)
System.Threading.Tasks.Task`1:RunContinuations()
System.Threading.Tasks.Task`1:TrySetResult(T)
System.Threading.Tasks.<Unwrap>c__AnonStorey1`1:<>m__1(Task`1)
System.Threading.Tasks.<ContinueWith>c__AnonStorey0:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey2:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey1:<>m__0()
System.Threading.Tasks.Task:<immediateExecutor>m__1(Action)
System.Threading.Tasks.Task:ContinueWith(Func`2, CancellationToken)
System.Threading.Tasks.<ContinueWith>c__AnonStorey0:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey2:<>m__0(Task)
System.Threading.Tasks.<ContinueWith>c__AnonStorey1:<>m__0()
System.Threading.Tasks.Task:<immediateExecutor>m__1(Action)
System.Threading.Tasks.Task`1:RunContinuations()
System.Threading.Tasks.Task`1:TrySetResult(T)
System.Threading.Tasks.<ContinueWith>c__AnonStorey1:<>m__0()
System.Threading.Tasks.Task:<immediateExecutor>m__1(Action)
System.Threading.Tasks.Task`1:RunContinuations()
System.Threading.Tasks.Task`1:TrySetResult(T)
System.Threading.Tasks.TaskCompletionSource`1:SetResult(T)
System.Threading.Tasks.<StartNew>c__AnonStorey0`1:<>m__0()
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
2018-12-11 18:00:01.156843+0800 firebasedemo[583:68296] DEBUG: FCM: Registered for remote notifications with device token
2018-12-11 18:00:01.158344+0800 firebasedemo[583:68296] FCM: Registered for remote notifications with device token
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
FCM: Registered for remote notifications with device token
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
2018-12-11 18:00:01.158462+0800 firebasedemo[583:68296] DEBUG: Searching for selector application:didRegisterForRemoteNotificationsWithDeviceToken: (FIRA380cc3b9application:didRegisterForRemoteNotificationsWithDeviceToken:) on class GUL_CustomUnityAppController-1544522401090
2018-12-11 18:00:01.158575+0800 firebasedemo[583:68296] Searching for selector application:didRegisterForRemoteNotificationsWithDeviceToken: (FIRA380cc3b9application:didRegisterForRemoteNotificationsWithDeviceToken:) on class GUL_CustomUnityAppController-1544522401090
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
Searching for selector application:didRegisterForRemoteNotificationsWithDeviceToken: (FIRA380cc3b9application:didRegisterForRemoteNotificationsWithDeviceToken:) on class GUL_CustomUnityAppController-1544522401090
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
2018-12-11 18:00:01.158628+0800 firebasedemo[583:68296] DEBUG: Found application:didRegisterForRemoteNotificationsWithDeviceToken: (FIRA380cc3b9application:didRegisterForRemoteNotificationsWithDeviceToken:, 0x05006ffc) on class GUL_CustomUnityAppController-1544522401090 (GUL_CustomUnityAppController-1544522401090)
2018-12-11 18:00:01.158698+0800 firebasedemo[583:68296] Found application:didRegisterForRemoteNotificationsWithDeviceToken: (FIRA380cc3b9application:didRegisterForRemoteNotificationsWithDeviceToken:, 0x05006ffc) on class GUL_CustomUnityAppController-1544522401090 (GUL_CustomUnityAppController-1544522401090)
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
Found application:didRegisterForRemoteNotificationsWithDeviceToken: (FIRA380cc3b9application:didRegisterForRemoteNotificationsWithDeviceToken:, 0x05006ffc) on class GUL_CustomUnityAppController-1544522401090 (GUL_CustomUnityAppController-1544522401090)
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
2018-12-11 18:00:01.173268+0800 firebasedemo[583:68296] @FirebaseUtility.LogTask RequestPermissionAsync: completed
2018-12-11 18:00:01.802582+0800 firebasedemo[583:68339] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C6.1:4][0x139e0e940] get output frames failed, state 8196
2018-12-11 18:00:01.802847+0800 firebasedemo[583:68339] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C6.1:4][0x139e0e940] get output frames failed, state 8196
2018-12-11 18:00:01.803390+0800 firebasedemo[583:68339] TIC Read Status [6:0x0]: 1:57
2018-12-11 18:00:01.803493+0800 firebasedemo[583:68339] TIC Read Status [6:0x0]: 1:57

0 个答案:

没有答案