Search code examples
iosswiftxcodeunity-game-engineonesignal

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


My problem:

I've made an game/app with Unity3D and need to setup OneSignal for push notifications. It works great with Android, I've tested and published that. Now, testing with iOs real device gives me a exception and crashes my app.

I followed their implementation steps found here: https://documentation.onesignal.com/docs/unity-sdk-setup

I've tried running on iPhone 7 Plus, iPad and Emulators. Emulators works great and registers on OneSignal (push doesn't work because it's not supported, but it's shown there). All other real devices crashes.

Also I'm not a objective-c/xcode/iOs expert AT ALL. I do know a lot of languages but objective-c is NOT one of them.

My Versions:

  • XCode Version 10.3 (10G8)
  • Unity Version 2019.2.5f1
  • OneSignal Unity SDK Version 2.8.2

My attempts:

Tried: Running on Android device

Result: Works great! No problems at all

--

Tried: Under Target > Capabilites: App Groups enabled, Background Modes/Remote Notifications enabled, Push Notifications enabled (like link above).

Result: App crashes at launch.

--

Tried: same as above, but with Wi-Fi turned off.

Result: Works, but OneSignal is not registered since it has no internet connection.

--

Tried: Under Target > Capabilites: App Groups enabled, Background Modes/Remote Notifications disabled, Push Notifications enabled.

Result: App launches and asks for Push Notifications Permission. Crashes when I allow it.

--

Tried: Enabling the same options above to the OneSignalNotificationServiceExtension target

Result: Nothing changes, crashes like before.

The error log:

In any crash, the same error occurs.

(I've changed the app name to APPNAME just for privacy of my client.)

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) 

Additional Details:

I don't know if it changes anything, but I get this error under Target > Capabilities > App Groups:

App Group errors

I tried disabling App Groups when building, but nothing changed.


Solution

  • I have the similar problem with version 2.8.2 and i've created issue for OneSignal developers: https://github.com/OneSignal/OneSignal-Unity-SDK/issues/218

    So this is sdk's bug.

    Solution: You can try to use OneSignal 2.8.1. It works for me.