iOs 使用 Unity3D 和 OneSignal 订阅推送通知时因 NSInvalidArgumentException 而崩溃

iOs crashing with NSInvalidArgumentException when subscribing for push notifications with Unity3D and OneSignal

我的问题:

我用 Unity3D 制作了一个 game/app 并且需要为推送通知设置 OneSignal。 它与 Android 配合使用效果很好,我已经测试并发布了它。现在,使用 iOs 真实设备进行测试会出现异常并使我的应用程序崩溃。

我遵循了他们在此处找到的实施步骤: https://documentation.onesignal.com/docs/unity-sdk-setup

我已经在 iPhone 7 Plus、iPad 和模拟器上尝试过 运行。仿真器运行良好并在 OneSignal 上注册(推送不起作用,因为它不受支持,但它显示在那里)。所有其他真实设备崩溃。

此外,我根本不是 objective-c/xcode/iOs 专家。我知道很多语言,但 objective-c 是 不是 其中之一。

我的版本:

我的尝试:

已尝试: 运行 在 Android 设备上

结果:效果很好!完全没问题

--

已尝试: 在目标 > 功能下:应用组 已启用,后台Modes/Remote 通知 已启用,推送通知 已启用(如上面的 link)。

结果: 应用程序在启动时崩溃。

--

已尝试: 与上述相同,但 Wi-Fi 已关闭

结果: 有效,但 OneSignal 未注册,因为它没有互联网连接。

--

已尝试: 在目标 > 功能下:应用组 已启用,后台Modes/Remote 通知 已禁用,推送通知 已启用。

结果: 应用程序启动并请求推送通知权限。当我允许时崩溃。

--

已尝试: 对 OneSignalNotificationServiceExtension 目标启用与上述相同的选项

结果:没有任何变化,像以前一样崩溃。

错误日志:

在任何崩溃中,都会发生相同的错误。

(我已将应用程序名称更改为 APPNAME 只是为了我客户的隐私。)

2019-09-12 13:33:05.883 APPNAME[1120:325776] UnityIAP UnityEarlyTransactionObserver: Created
2019-09-12 13:33:05.890 APPNAME[1120:325776] UnityIAP UnityEarlyTransactionObserver: Registered for lifecycle events
CrashReporter: initialized
2019-09-12 13:33:06.180 APPNAME[1120:325776] Built from '2019.2/staging' branch, Version '2019.2.5f1 (9dace1eed4cc)', Build type 'Release', Scripting Backend 'il2cpp'
2019-09-12 13:33:06.219 APPNAME[1120:325776] -> registered mono modules 0x158e810
2019-09-12 13:33:06.471 APPNAME[1120:325776] 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.
-> applicationDidFinishLaunching()
2019-09-12 13:33:06.978 APPNAME[1120:325776] Metal GPU Frame Capture Enabled
2019-09-12 13:33:06.979 APPNAME[1120:325776] Metal API Validation Disabled
2019-09-12 13:33:07.507 APPNAME[1120:325776] UnityIAP UnityEarlyTransactionObserver: Added to the payment queue
-> applicationDidBecomeActive()
[XR] Discovering subsystems at path /var/containers/Bundle/Application/493D8CF2-4D91-4035-9256-8E7A53D7FB4A/APPNAME.app/Data/UnitySubsystems
GfxDevice: creating device client; threaded=1
Renderer: PowerVR SGX 543
Vendor:   Imagination Technologies
Version:  OpenGL ES 2.0 IMGSGX543-124.1
GLES:     2
 GL_OES_depth_texture GL_OES_depth24 GL_OES_element_index_uint GL_OES_fbo_render_mipmap GL_OES_mapbuffer GL_OES_packed_depth_stencil GL_OES_rgb8_rgba8 GL_OES_standard_derivatives GL_OES_texture_float GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_vertex_array_object GL_EXT_blend_minmax GL_EXT_color_buffer_half_float GL_EXT_debug_label GL_EXT_debug_marker GL_EXT_discard_framebuffer GL_EXT_draw_instanced GL_EXT_instanced_arrays GL_EXT_map_buffer_range GL_EXT_occlusion_query_boolean GL_EXT_pvrtc_sRGB GL_EXT_read_format_bgra GL_EXT_separate_shader_objects GL_EXT_shader_framebuffer_fetch GL_EXT_shader_texture_lod GL_EXT_shadow_samplers GL_EXT_sRGB GL_EXT_texture_filter_anisotropic GL_EXT_texture_rg GL_EXT_texture_storage GL_APPLE_clip_distance GL_APPLE_color_buffer_packed_float GL_APPLE_copy_texture_levels GL_APPLE_framebuffer_multisample GL_APPLE_rgb_422 GL_APPLE_sync GL_APPLE_texture_format_BGRA8888 GL_APPLE_texture_max_level GL_APPLE_texture_packed_float GL_IMG_read_format GL_IMG_texture_com
pression_pvrtc
OPENGL LOG: Creating OpenGL ES 2.0 graphics device ; Context level  <OpenGL ES 2.0> ; Context handle 359478480
Initialize engine version: 2019.2.5f1 (9dace1eed4cc)
CrashReporter: No pending report exists at /var/mobile/Containers/Data/Application/FF47706A-E2CD-4895-8DDC-0C80ECA7CD0D/Library/Caches/CrashReports/crash-pending.plcrash
2019-09-12 13:33:09.173 APPNAME[1120:325776] WARNING: OneSignal has detected that your application delegate implements a deprecated method (application:didReceiveLocalNotification:). Please note that this method has been officially deprecated and the OneSignal SDK will no longer call it. You should use UNUserNotificationCenter instead
2019-09-12 13:33:09.176 APPNAME[1120:325776] WARNING: OneSignal has detected that your application delegate implements a deprecated method (application:handleActionWithIdentifier:forLocalNotification:completionHandler:). Please note that this method has been officially deprecated and the OneSignal SDK will no longer call it. You should use UNUserNotificationCenter instead
UnloadTime: 24.191250 ms
Initializing UnityPurchasing via Codeless IAP
UnityEngine.Purchasing.CodelessIAPStoreListener:get_Instance()

(Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)

UnityIAP Version: 1.22.0
UnityEngine.Purchasing.StandardPurchasingModule:Instance(AppStore)
UnityEngine.Purchasing.CodelessIAPStoreListener:get_Instance()

(Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)

2019-09-12 13:33:12.759 APPNAME[1120:325776] WARNING: OneSignal has detected that your application delegate implements a deprecated method (application:didReceiveLocalNotification:). Please note that this method has been officially deprecated and the OneSignal SDK will no longer call it. You should use UNUserNotificationCenter instead
2019-09-12 13:33:12.760 APPNAME[1120:325776] WARNING: OneSignal has detected that your application delegate implements a deprecated method (application:handleActionWithIdentifier:forLocalNotification:completionHandler:). Please note that this method has been officially deprecated and the OneSignal SDK will no longer call it. You should use UNUserNotificationCenter instead
-> applicationWillResignActive()
-> applicationDidBecomeActive()
Using configuration builder objects
UnityEngine.Purchasing.StoreCatalogImpl:handleCachedCatalog(Action`1)
UnityEngine.Purchasing.<Process>d__4:System.IDisposable.Dispose()

(Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)

2019-09-12 13:33:15.912 APPNAME[1120:325776] UnityIAP: Requesting 1 products
2019-09-12 13:33:15.915 APPNAME[1120:325776] UnityIAP: Requesting product data...
2019-09-12 13:33:17.167 APPNAME[1120:325776] UnityIAP: Received 1 products
2019-09-12 13:33:17.192 APPNAME[1120:325776] UnityIAP: No App Receipt found
2019-09-12 13:33:17.207 APPNAME[1120:325776] UnityIAP: No App Receipt found
UnityIAP: Promo interface is available for 1 items
UnityEngine.Purchasing.Promo:ProvideProductsToAds(HashSet`1)
UnityEngine.Purchasing.AppleStoreImpl:OnProductsRetrieved(String)
System.Action:Invoke()
UnityEngine.Purchasing.Extension.UnityUtil:Update()

(Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)

2019-09-12 13:33:17.219 APPNAME[1120:325776] UnityIAP: Add transaction observer
2019-09-12 13:33:17.221 APPNAME[1120:325776] UnityIAP UnityEarlyTransactionObserver: Request to initiate queued payments
2019-09-12 13:33:19.375 APPNAME[1120:325776] +[NSString hexStringFromData:]: unrecognized selector sent to class 0x3b1c52dc
2019-09-12 13:33:19.791 APPNAME[1120:325776] Uncaught exception: NSInvalidArgumentException: +[NSString hexStringFromData:]: unrecognized selector sent to class 0x3b1c52dc
(
    0   CoreFoundation                      0x2406f933 <redacted> + 150
    1   libobjc.A.dylib                     0x2380ae17 objc_exception_throw + 38
    2   CoreFoundation                      0x240751d1 <redacted> + 0
    3   CoreFoundation                      0x24072ee1 <redacted> + 700
    4   CoreFoundation                      0x23f9e238 _CF_forwarding_prep_0 + 24
    5   APPNAME                     0x014af3c9 +[OneSignal didRegisterForRemoteNotifications:deviceToken:] + 90
    6   APPNAME                     0x014c1447 -[OneSignalAppDelegate oneSignalDidRegisterForRemoteNotifications:deviceToken:] + 90
    7   libdispatch.dylib                   0x23bdd823 <redacted> + 10
    8   libdispatch.dylib                   0x23bdd80f <redacted> + 22
    9   libdispatch.dylib                   0x23bebba9 <redacted> + 1524
    10  Cowarning: could not execute support code to read Objective-C class data in the process. This may reduce the quality of type information available.
reFoundation                      0x24031b6d <redacted> + 8
    11  CoreFoundation                      0x24030067 <redacted> + 1574
    12  CoreFoundation                      0x23f7f229 CFRunLoopRunSpecific + 520
    13  CoreFoundation                      0x23f7f015 CFRunLoopRunInMode + 108
    14  GraphicsServices                    0x2556fac9 GSEventRunModal + 160
    15  UIKit                               0x28653189 UIApplicationMain + 144
    16  APPNAME                     0x000844bb main + 202
    17  libdyld.dylib                       0x23c27873 <redacted> + 2
)
(lldb) 

其他详细信息:

我不知道它是否改变了什么,但我在“目标”>“功能”>“应用程序组”下收到此错误:

我尝试在构建时禁用应用程序组,但没有任何改变。

我在 2.8.2 版本中遇到了类似的问题,我已经为 OneSignal 开发人员创建了问题: https://github.com/OneSignal/OneSignal-Unity-SDK/issues/218

原来是sdk的bug

解决方案:你可以试试用OneSignal 2.8.1.我用的很好