OneSignal / OneSignal-Unity-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Unity app with OneSignal. https://onesignal.com
Other
222 stars 61 forks source link

[Bug]: NSInvalidArgumentException Xcode #748

Closed RudieCph closed 3 months ago

RudieCph commented 3 months ago

What happened?

When I build the app for iOS in Xcode 15.4 it crashes on launch with the error "NSInvalidArgumentException". I am able to build the app without OneSignal

Steps to reproduce?

1. Install OneSignal  Unity SDK - Core, Android & iOS v 5.1.7
2. Build in Unity.
3. Register all signing & capabilities - App Groups
4. Certificates generated and approved.
5. Build and Run in XCode
6. Crashes as soon as the splash screen opens.

What did you expect to happen?

The app has worked in earlier versions with OneSignal and iOS, but now I cannot run the app as it crashes as soon as the splash screen with "made with unity" opens.

Unity version

2022.3.11f1

OneSignal Unity SDK version

5.1.7

Platform

iOS

Relevant log output

Couldn't read values in CFPrefsPlistSource<0x303e44d80> (Domain: group.com.appname.onesignal, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd
UnityIAP UnityEarlyTransactionObserver: Created
UnityIAP UnityEarlyTransactionObserver: Registered for lifecycle events
CrashReporter: initialized
Built from '2022.3/staging' branch, Version '2022.3.11f1 (d00248457e15)', Build type 'Release', Scripting Backend 'il2cpp'
MemoryManager: Using 'Default' Allocator.
[UnityMemory] Configuration Parameters - Can be set up in boot.config
    "memorysetup-allocator-temp-initial-block-size-main=262144"
    "memorysetup-allocator-temp-initial-block-size-worker=262144"
    "memorysetup-bucket-allocator-granularity=16"
    "memorysetup-bucket-allocator-bucket-count=8"
    "memorysetup-bucket-allocator-block-size=4194304"
    "memorysetup-bucket-allocator-block-count=1"
    "memorysetup-main-allocator-block-size=16777216"
    "memorysetup-thread-allocator-block-size=16777216"
    "memorysetup-gfx-main-allocator-block-size=16777216"
    "memorysetup-gfx-thread-allocator-block-size=16777216"
    "memorysetup-cache-allocator-block-size=4194304"
    "memorysetup-typetree-allocator-block-size=2097152"
    "memorysetup-profiler-bucket-allocator-granularity=16"
    "memorysetup-profiler-bucket-allocator-bucket-count=8"
    "memorysetup-profiler-bucket-allocator-block-size=4194304"
    "memorysetup-profiler-bucket-allocator-block-count=1"
    "memorysetup-profiler-allocator-block-size=16777216"
    "memorysetup-profiler-editor-allocator-block-size=1048576"
    "memorysetup-temp-allocator-size-main=4194304"
    "memorysetup-job-temp-allocator-block-size=2097152"
    "memorysetup-job-temp-allocator-block-size-background=1048576"
    "memorysetup-job-temp-allocator-reduction-small-platforms=262144"
    "memorysetup-temp-allocator-size-background-worker=32768"
    "memorysetup-temp-allocator-size-job-worker=262144"
    "memorysetup-temp-allocator-size-preload-manager=262144"
    "memorysetup-temp-allocator-size-nav-mesh-worker=65536"
    "memorysetup-temp-allocator-size-audio-worker=65536"
    "memorysetup-temp-allocator-size-cloud-worker=32768"
    "memorysetup-temp-allocator-size-gfx=262144"
FATAL: OneSignal AppId: (null) - AppId is null or format is invalid, stopping initialization.
Example usage: 'b2f7f966-d8cc-11e4-bed1-df8f05be55ba'
-> applicationDidFinishLaunching()
[Physics::Module] Initialized MultithreadedJobDispatcher with 5 workers.
UnityIAP UnityEarlyTransactionObserver: Added to the payment queue
-> applicationDidBecomeActive()
GfxDevice: creating device client; threaded=1; jobified=0
Initializing Metal device caps: Apple A14 GPU
Initialize engine version: 2022.3.11f1 (d00248457e15)
CrashReporter: No pending report exists at /var/mobile/Containers/Data/Application/D84DD1D0-9214-45E2-96DF-2FA2990C92F8/Library/Caches/CrashReports/crash-pending.plcrash
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[1]'
*** First throw call stack:
(0x197130f20 0x18efde018 0x1970c0344 0x1970c14d8 0x10059cc14 0x19efd413c 0x19efd5dd4 0x19efe45a4 0x19efe41b8 0x197103710 0x197100914 0x1970ffcd8 0x1dbfb01a8 0x19973890c 0x1997ec9d0 0x108c076d4 0x10025412c 0x1ba7b1e4c)
Uncaught exception: NSInvalidArgumentException: *** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[1]
(
    0   CoreFoundation                      0x0000000197130f2c 00E76A98-210C-3CB5-930B-F236807FF24C + 540460
    1   libobjc.A.dylib                     0x000000018efde018 objc_exception_throw + 60
    2   CoreFoundation                      0x00000001970c0344 00E76A98-210C-3CB5-930B-F236807FF24C + 78660
    3   CoreFoundation                      0x00000001970c14d8 00E76A98-210C-3CB5-930B-F236807FF24C + 83160
    4   OneSignalNotifications              0x000000010059cc14 -[OneSignalNotificationsAppDelegate oneSignalDidFailRegisterForRemoteNotification:error:] + 200
    5   libdispatch.dylib                   0x000000019efd413c 81D355DF-266A-3010-BAB8-113B76A206C1 + 8508
    6   libdispatch.dylib                   0x000000019efd5dd4 81D355DF-266A-3010-BAB8-113B76A206C1 + 15828
    7   libdispatch.dylib                   0x000000019efe45a4 81D355DF-266A-3010-BAB8-113B76A206C1 + 75172
    8   libdispatch.dylib                   0x000000019efe41b8 _dispatch_main_queue_callback_4CF + 44
    9   CoreFoundation                      0x0000000197103710 00E76A98-210C-3CB5-930B-F236807FF24C + 354064
    10  CoreFoundation                      0x0000000197100914 00E76A98-210C-3CB5-930B-F236807FF24C + 342292
    11  CoreFoundation                      0x00000001970ffcd8 CFRunLoopRunSpecific + 608
    12  GraphicsServices                    0x00000001dbfb01a8 GSEventRunModal + 164
    13  UIKitCore                           0x000000019973890c 1741FA37-4E53-371E-8DAE-D611AAB0043D + 4237580
    14  UIKitCore                           0x00000001997ec9d0 UIApplicationMain + 340
    15  UnityFramework                      0x0000000108c076d4 -[UnityFramework runUIApplicationMainWithArgc:argv:] + 92
    16  Appname             0x000000010025412c main + 60
    17  dyld                                0x00000001ba7b1e4c 71846EAC-EE65-3697-BF7D-790B6A07DCDB + 249420
)

Code of Conduct

shepherd-l commented 3 months ago

Thanks for reporting.

Could you turn on verbose logging and share your log output again?

You can turn on verbose logging by calling OneSignal.Debug.LogLevel = LogLevel.Verbose; before OneSignal.Initialize(appId);

For context, the log FATAL: OneSignal AppId: (null) ... is a misleading but expected log for our Unity SDK. It prints from our integration of our wrapper SDKs with our native iOS SDK.

RudieCph commented 3 months ago

I turned on the Verbose log level now, but I am not sure the log is different. I tried with a totally clean build with no OneSignal again, and it works flawlessly. Then when I add OneSignal to the app it freezes on launch.

Here is the log:

Couldn't read values in CFPrefsPlistSource<0x3037e0b40> (Domain: group.appname.onesignal, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd
UnityIAP UnityEarlyTransactionObserver: Created
UnityIAP UnityEarlyTransactionObserver: Registered for lifecycle events
CrashReporter: initialized
Built from '2022.3/staging' branch, Version '2022.3.11f1 (d00248457e15)', Build type 'Release', Scripting Backend 'il2cpp'
MemoryManager: Using 'Default' Allocator.
[UnityMemory] Configuration Parameters - Can be set up in boot.config
    "memorysetup-allocator-temp-initial-block-size-main=262144"
    "memorysetup-allocator-temp-initial-block-size-worker=262144"
    "memorysetup-bucket-allocator-granularity=16"
    "memorysetup-bucket-allocator-bucket-count=8"
    "memorysetup-bucket-allocator-block-size=4194304"
    "memorysetup-bucket-allocator-block-count=1"
    "memorysetup-main-allocator-block-size=16777216"
    "memorysetup-thread-allocator-block-size=16777216"
    "memorysetup-gfx-main-allocator-block-size=16777216"
    "memorysetup-gfx-thread-allocator-block-size=16777216"
    "memorysetup-cache-allocator-block-size=4194304"
    "memorysetup-typetree-allocator-block-size=2097152"
    "memorysetup-profiler-bucket-allocator-granularity=16"
    "memorysetup-profiler-bucket-allocator-bucket-count=8"
    "memorysetup-profiler-bucket-allocator-block-size=4194304"
    "memorysetup-profiler-bucket-allocator-block-count=1"
    "memorysetup-profiler-allocator-block-size=16777216"
    "memorysetup-profiler-editor-allocator-block-size=1048576"
    "memorysetup-temp-allocator-size-main=4194304"
    "memorysetup-job-temp-allocator-block-size=2097152"
    "memorysetup-job-temp-allocator-block-size-background=1048576"
    "memorysetup-job-temp-allocator-reduction-small-platforms=262144"
    "memorysetup-temp-allocator-size-background-worker=32768"
    "memorysetup-temp-allocator-size-job-worker=262144"
    "memorysetup-temp-allocator-size-preload-manager=262144"
    "memorysetup-temp-allocator-size-nav-mesh-worker=65536"
    "memorysetup-temp-allocator-size-audio-worker=65536"
    "memorysetup-temp-allocator-size-cloud-worker=32768"
    "memorysetup-temp-allocator-size-gfx=262144"
FATAL: OneSignal AppId: (null) - AppId is null or format is invalid, stopping initialization.
Example usage: 'b2f7f966-d8cc-11e4-bed1-df8f05be55ba'
-> applicationDidFinishLaunching()
[Physics::Module] Initialized MultithreadedJobDispatcher with 5 workers.
UnityIAP UnityEarlyTransactionObserver: Added to the payment queue
-> applicationDidBecomeActive()
GfxDevice: creating device client; threaded=1; jobified=0
Initializing Metal device caps: Apple A14 GPU
Initialize engine version: 2022.3.11f1 (d00248457e15)
CrashReporter: No pending report exists at /var/mobile/Containers/Data/Application/F0E6184A-9ED5-40BB-BD65-56BEC83A9042/Library/Caches/CrashReports/crash-pending.plcrash
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[1]'
*** First throw call stack:
(0x197130f20 0x18efde018 0x1970c0344 0x1970c14d8 0x105640c14 0x19efd413c 0x19efd5dd4 0x19efe45a4 0x19efe41b8 0x197103710 0x197100914 0x1970ffcd8 0x1dbfb01a8 0x19973890c 0x1997ec9d0 0x10dbc776c 0x104e4c12c 0x1ba7b1e4c)
Uncaught exception: NSInvalidArgumentException: *** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[1]
(
    0   CoreFoundation                      0x0000000197130f2c 00E76A98-210C-3CB5-930B-F236807FF24C + 540460
    1   libobjc.A.dylib                     0x000000018efde018 objc_exception_throw + 60
    2   CoreFoundation                      0x00000001970c0344 00E76A98-210C-3CB5-930B-F236807FF24C + 78660
    3   CoreFoundation                      0x00000001970c14d8 00E76A98-210C-3CB5-930B-F236807FF24C + 83160
    4   OneSignalNotifications              0x0000000105640c14 -[OneSignalNotificationsAppDelegate oneSignalDidFailRegisterForRemoteNotification:error:] + 200
    5   libdispatch.dylib                   0x000000019efd413c 81D355DF-266A-3010-BAB8-113B76A206C1 + 8508
    6   libdispatch.dylib                   0x000000019efd5dd4 81D355DF-266A-3010-BAB8-113B76A206C1 + 15828
    7   libdispatch.dylib                   0x000000019efe45a4 81D355DF-266A-3010-BAB8-113B76A206C1 + 75172
    8   libdispatch.dylib                   0x000000019efe41b8 _dispatch_main_queue_callback_4CF + 44
    9   CoreFoundation                      0x0000000197103710 00E76A98-210C-3CB5-930B-F236807FF24C + 354064
    10  CoreFoundation                      0x0000000197100914 00E76A98-210C-3CB5-930B-F236807FF24C + 342292
    11  CoreFoundation                      0x00000001970ffcd8 CFRunLoopRunSpecific + 608
    12  GraphicsServices                    0x00000001dbfb01a8 GSEventRunModal + 164
    13  UIKitCore                           0x000000019973890c 1741FA37-4E53-371E-8DAE-D611AAB0043D + 4237580
    14  UIKitCore                           0x00000001997ec9d0 UIApplicationMain + 340
    15  UnityFramework                      0x000000010dbc776c -[UnityFramework runUIApplicationMainWithArgc:argv:] + 92
    16                                                   0x0000000104e4c12c main + 60
    17  dyld                                0x00000001ba7b1e4c 71846EAC-EE65-3697-BF7D-790B6A07DCDB + 249420
)
RudieCph commented 3 months ago

The app builds and runs fine on Android, also with OneSignal installed.

shepherd-l commented 3 months ago

It looks like you didn't set up verbose logging correctly, you should be seeing some logs like "VERBOSE: ..."

Could you make sure that either your Start() or Awake() method look something like this?

private void Start() {
    OneSignal.Debug.LogLevel = LogLevel.Verbose;

    OneSignal.Initialize(ONESIGNAL_APP_ID);
}
RudieCph commented 3 months ago

Hi again. I have both tried to set the verbose loglevel both with the standard example gameobject and with a custom script. But it gives the same log. I don't know if it's because it crashes even before any of those logs appear? Again this happens only with OneSignal. It's a shame as I have quite some subscribers in OneSignal already, but I need the new update released, so I am considering if I need to drop OneSignal.

RudieCph commented 3 months ago

The app also crashes on iOS if I never initialize the onesignal via the script, but just have the onesignal extension added in the unity assets and in the Xcode workspace. So maybe that's why there's no verbose logging because the crash happens before those scripts are even loaded?

shepherd-l commented 3 months ago

Thanks for the update

Taking a look at your log again, it looks like you might be having an issue with APNS: https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622962-application

UIKit calls this method if it was unable to register your app with APNs or if your app is not properly configured for remote notifications. During development, make sure your app has the proper entitlements and that its App ID is configured to support push notifications. You might use your implementation of this method to make a note of the failed registration so that you can try again later.

For context, the above method is called from this log which indicates that you may not have something APNS requires

4   OneSignalNotifications              0x0000000105640c14 -[OneSignalNotificationsAppDelegate oneSignalDidFailRegisterForRemoteNotification:error:] + 200

The OneSignal SDK uses swizzling so when didFailToRegisterForRemoteNotificationsWithError is fired, it just forwards it to oneSignalDidFailRegisterForRemoteNotification (source here).

What I think is happening here is that even though the OneSignal Fatal log prints (which is expected), it never gets to verbose logging because the app crashes early due to incorrect APNS configuration. And that your app also still crashes without calling OneSignal due to the APNS error.

I recommend following what Apple suggests to check for in their docs as mentioned above.

nan-li commented 3 months ago

Hi @RudieCph, Your app appeared to be unable to register for push notifications, but this may be misleading.

The problem is that Apple is giving us a null NSError, when it should never be null. This might indicate an Apple bug. If provisioning profile is wrong or the app is missing push capability, we should get an error saying that.

I found this forum that discusses this null error possibly related to Product Name on ios 14: https://forums.developer.apple.com/forums/thread/660715

See the Apple Engineer’s response, does this apply to your app?

As some of you have found out, this issue is is being caused on iOS 14 if the Product Name (not the Display Name) contain certain characters. Unfortunately this issue causes problems with the complete alphabets of several languages, as well as certain special characters.

If you encounter this issue, you will see two distinct errors related to User Notifications. ...

RudieCph commented 3 months ago

Thanks a

Hi @RudieCph, Your app appeared to be unable to register for push notifications, but this may be misleading.

The problem is that Apple is giving us a null NSError, when it should never be null. This might indicate an Apple bug. If provisioning profile is wrong or the app is missing push capability, we should get an error saying that.

I found this forum that discusses this null error possibly related to Product Name on ios 14: https://forums.developer.apple.com/forums/thread/660715

See the Apple Engineer’s response, does this apply to your app?

As some of you have found out, this issue is is being caused on iOS 14 if the Product Name (not the Display Name) contain certain characters. Unfortunately this issue causes problems with the complete alphabets of several languages, as well as certain special characters. If you encounter this issue, you will see two distinct errors related to User Notifications. ...

Thanks a lot! This was the case as I used a Danish "Å" in the product name! So for anyone using Special Characters in the Product Name, take care.

It has never been a problem with earlier builds, so I had no idea this would have all of a sudden caused a complete crash.

Once again thanks a lot for saving the day!

Kind regards Rune