My app keeps crashing at launch (maybe 5% of the time) when the SDK calls this method in file OneSignalSelectorHelpers.m:
NSArray* ClassGetSubclasses(Class parentClass) {
int numClasses = objc_getClassList(NULL, 0);
Class *classes = NULL;
classes = (Class *)malloc(sizeof(Class) * numClasses);
numClasses = objc_getClassList(classes, numClasses);
NSMutableArray *result = [NSMutableArray array];
for (NSInteger i = 0; i < numClasses; i++) {
Class superClass = classes[i];
do {
superClass = class_getSuperclass(superClass);
} while(superClass && superClass != parentClass);
if (superClass == nil) continue;
[result addObject:classes[i]];
}
free(classes);
return result;
}
The crash occurs in this line:
superClass = class_getSuperclass(superClass);
@jstheoriginal Can you provide the full stack trace of the crash? Include the iOS version, OneSignal SDK version, and if you are using any other frameworks in your project.
Can you reproduce the issue in a new Xcode project?
Same here, although it's more like 50% of the time. This is with Xcode 9 GM and iOS 11, and latest SDK version. If I run the app using the iOS 10 simulator it's fine. I removed all calls to OneSignal and left the framework, and it still crashed.
Will grab the stack trace once it happens again.
I鈥檓 using the latest version of OneSignal.
And I only call a single OneSignal method in my app on a pushed screen (it never crashes then...always before the app has finished launching, so it must be some OneSignal Singleton init issue).
Like Laurent says, it鈥檚 onky happening on iOS 11 and happens on the Xcode 9 GM release.
I think it might only happen in the simulator.
Laurent: have you had it crash on physical device or just in the sim?
Same here, This is with Xcode 9 GM/iOS 11, and latest SDK version. Also exact situation as @jstheoriginal. I got the following back trace
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x7)
frame #0: 0x0000000114c0a114 libobjc.A.dylib`class_getSuperclass + 5
frame #1: 0x000000010ff1d4e8 Memeois`ClassGetSubclasses(parentClass=OneSignal) at OneSignalSelectorHelpers.m:104
frame #2: 0x000000010ff214b8 Memeois`-[OneSignalUNUserNotificationCenter setOneSignalUNDelegate:](self=0x000060400003dfe0, _cmd="setDelegate:", delegate=0x000060000001e2b0) at UNUserNotificationCenter+OneSignal.m:126
frame #3: 0x000000010ff188a6 Memeois`+[OneSignalHelper registerAsUNNotificationCenterDelegate](self=OneSignalHelper, _cmd="registerAsUNNotificationCenterDelegate") at OneSignalHelper.m:726
* frame #4: 0x000000010ff1000a Memeois`+[UIApplication(self=UIApplication, _cmd="load") load] at OneSignal.m:1620
frame #5: 0x0000000114c0c4d0 libobjc.A.dylib`call_load_methods + 236
frame #6: 0x0000000114c0d2f3 libobjc.A.dylib`load_images + 70
frame #7: 0x0000000110344dac dyld_sim`dyld::notifySingle(dyld_image_states, ImageLoader const*, ImageLoader::InitializerTimingList*) + 407
frame #8: 0x00000001103516c5 dyld_sim`ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 309
frame #9: 0x0000000110350898 dyld_sim`ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 134
frame #10: 0x000000011035092c dyld_sim`ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) + 74
frame #11: 0x000000011034517b dyld_sim`dyld::initializeMainExecutable() + 196
frame #12: 0x0000000110348c98 dyld_sim`dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) + 4412
frame #13: 0x00000001103443d4 dyld_sim`start_sim + 136
frame #14: 0x000000011b9f6510 dyld`dyld::useSimulatorDyld(int, macho_header const*, char const*, int, char const**, char const**, char const**, unsigned long*, unsigned long*) + 2246
frame #15: 0x000000011b9f4a39 dyld`dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) + 241
frame #16: 0x000000011b9f0249 dyld`dyldbootstrap::start(macho_header const*, int, char const**, long, macho_header const*, unsigned long*) + 470
frame #17: 0x000000011b9f0036 dyld`_dyld_start + 54
@anushkmittal @laurent-humbert I tried reproducing this issue with the latest GM of iOS 11.0 and Xcode 9 without success. Both with Carthage builds and Cocoapods. As well as on a simulator and a real device.
Can you try example project or a clean new Xcode to see if the crash still happens for you?
https://github.com/OneSignal/OneSignal-iOS-SDK/tree/master/Examples
Please let us know all other frameworks you are using in your project. Lastly are you using UNNotificationCenterDelegate any where in your code?
Did you try it out on an iPhone X simulator? Also, I ran a workspace search for UNNotification and the only occurrences were in OneSignalNotificationServiceExtension. I'll link the reproducible Xcode project soon
@anushkmittal Was testing on an iPhone 8 simulator and an a real iPhone 6 on iOS 10.0. Just tried an iPhone X simulator without any issues. The device models shouldn't be a factor.
What method did you use the setup the OneSignal SDK? Cocoapods, Carthage, or manually?
I鈥檓 using Carthage to install the SDK.
I did a manual install. I just grabbed the iOS_SDK/OneSignalSDK/Framework/OneSignal.framework file from the SDK and added it to both the app and notification extension targets.
Today I also added Foundation.framework, CFNetwork.framework, SystemConfiguration.framework and UIKit.framework to the extension target, and it looks like it fixed the problem....
@laurent-humbert Odd that Xcode isn't getting a link error without those 4 frameworks added to the project. When it was crashing was it also happening on class_getSuperclass? If you still have the stack trace saved was it the same as "anushkmittal"'s?
Did the crash only happen when ran the extension target? Or only when you receive a notification with mutable-content enabled, action buttons, or media attachment feature?
I wasn't sending any push notifications when it crashes...it just crashes on app launch. Seems to be unrelated to actual pushes coming in at all.
@jstheoriginal Does launching your app from Xcode through the normal app target vs the notification extension have an effect if crashes or not?
I don't have an extension...just a normal app target.
These are the frameworks I use:

Just happened to me on the simulator (iPhone 6, Xcode 9):

Using OneSignal (2.5.4)
The issue is now fixed in master. It will be included in the next release.
When is the next release planned? Should we in the meanwhile use master or is this not recommended? I am releasing a new version of my app in the next days...
Also experiencing crashes on launch on simulator - sometimes often sometimes rarely. Haven't tried on device. Pulled in the framework gerbiljames kindly built on his fork (https://github.com/OneSignal/OneSignal-iOS-SDK/issues/278#issuecomment-332208704)
which has the aforementioned fix, but the issue still happening for me and the second iOS dev in office.

Yeah it's still happening for me too with the framework on my fork. We got through approval using it though so we were either lucky or it doesnt happen on device.
Do you have crashreporting in you appon the store? Could you use it to verify that it does not crash on the actual device?
I am also getting the same error after applying the fix. I will try and generate a crashreport to see whats up
Just jumping in to confirm I am having this exact same issue.
Version 2.5.5 has been released to CocoaPods with a fix for this.
If their are any future issues please post to issue https://github.com/OneSignal/OneSignal-iOS-SDK/issues/278 instead.
Most helpful comment
When is the next release planned? Should we in the meanwhile use master or is this not recommended? I am releasing a new version of my app in the next days...