App crash after registerForPushNotifications on iOS - FIRInstanceID setAPNSToken:type:

Hello Rob and all the coronalabs community, 

I tried to return the problem in all directions before posting here but I have not managed to solve my problem.

We have developed a suite of applications (one for each city) that is still based on the same model and that worked well until then.

For notifications, we use the V2 notification plugin with Firebase Cloud Messaging and it worked very well so far.

But today we encounter a problem on our apps that we have recently builded (with 2018.3363), only on iOS (it work on Android).

Once on the iOS device, the applications closes at boot time, as soon as it tries to registerForPushNotifications.

local function notificationListener( event ) ... end Runtime:addEventListener( "notification", notificationListener )  notifications.registerForPushNotifications({ useFCM=true })

We have this error apparently:

Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: '-[FIRInstanceID setAPNSToken:type:]

: unrecognized selector sent to instance 0x1c40b81e0

However, we followed our usual process for the management of Firebase accounts and for the creation of various necessary keys (Firebase, APNs, GoogleService-Info.plist …).

In short, we do not understand where the problem come from … and a little help would be appreciated. Someone would know where the mistake can come from? Did we do something wrong? Is this a possible bug?

Thank you in advance for all future help you can bring me.

Have a nice day!

PS: Sorry for my bad english

Hello community,

I allow myself to post again because we still have not found an answer to our problem, and our client may lose patience.

We have downloaded the latest Corona daily build, updated Xcode and retried to build and the result is still the same.

Has Apple changed anything on its side with the upcoming arrival of iOS 12?

Has anyone encountered the same problem … and maybe found a solution? 

The problem does not seem to concern only our latest new application.

We tried to build again our old applications that worked perfectly until then (created on the same model) and we also meet the same problem.

Thank you very much for the help you can give me.

Can you put together a sample project that demonstrates the problem and use the Report a Bug feature at the top of the screen.

It needs to be a project that our engineers can build and run on a device, so provide a main.lua, config.lua, build.settings and other necessary files in a .zip file along with details on how to setup and run the project.

Thanks

Rob

I have been unable to release my new app due to this problem. I thought this was related to the firebase.analytics plugin, but after disabling that, the notification does exit the app immediate after bringing up the ALLOW or DISALLOW dialog. Imagine that the allow or disallow dialog comes up and then behind it, your app closes. Makes no sense.

FYI, I’m using build 3366 (3 versions newer from GBF Comm)

Hello Rob, Bektur, troylyndon and community!

We submitted the bug report with a sample code leaving only V2 notification and FirebaseAnalytics. We had a feedback saying to try without the Scott Harrison firebase Analytics plugin. We have indeed tried without this plugin and it works. No more crash! and the the ALLOW or DISALLOW dialog works.

So it looks like Scott Harrison’s Firebase Analytics plugin is causing the problem and crashing at notifications.registerForPushNotifications ({useFCM = true}).

We already had a problem of cohabitation of the two plugin. We understood that it was imperative to perform the initialization of Analytics firebase a few seconds after the call to notifications. So with a timer.performWithDelay everything worked until then.

Apparently this does not work anymore and we must now find how to succeed in making both plugins live together.

would anyone have an idea? do you know if scott Harrison is actively following the Corona forums?

This is two major plugin for Corona and the fact that it can no longer cohabit together is really a problem for us. :frowning:

Hello,

I continued my tests and I arrived at this observation:

By cleaning any call to Firebase Analytics in my .lua files but leaving only the call to the plugin in the build.settings we have the crash.

plugins =     {                  ["plugin.firebaseAnalytics"] = {           publisherId = "tech.scotth",         },         ["plugin.notifications.v2"] =         {             publisherId = "com.coronalabs",         },     },

 

Apparently, The problem does not come from our code but an incompatibility between the two plugins during compilation.

@Scott Harrison please help!

@troylyndon, @GBF Comm,

I’m kind of confused now. Troy you say removing the Analytics plugin causes the app to still crash. @GBF you say removing the Analytics plugin solves the problem. 

@troylyndon do you have a sample app that demos this crash? (stripped down app). If you do, it might be worth the two of you sharing each other’s test case and get independent verification. Maybe it will help narrow down what the difference is between your two experiences.

The only one who can address problems with Scott’s plugins is Scott. I can’t speak to how much he monitors the forums, but the marketplace should have contact information for him as well as his support channels. It’s best you reach out directly to him. 

Rob

@Rob Miracle.

Yes, totally removing the Analytics plugin solves the problem. As i said before in my previous post, juste leaving the declaration in Build.settings cause the crash. Perhaps troylyndon doesn’t remove the plugin decalaration in the build.settings? Do you troylyndon?

I sent to scott harrison a mail with sample files to reproduce the problem. It only remains for me to wait for his answer. I will keep you informed on this topic of the continuation and, I hope, of the resolution of the problem.

Thanks
GBF Comm

@Rob, @GBF Comm,
Yes, there is no doubt there is a PLUGIN CONFLICT between Firebase and Notifications. With that said, let me explain what I have working and what I’m waiting on Scott and Rob to fix.

PRIORITIES
For iOS, I’ve decided it’s more important for me to run Firebase (and track device app launching) than to have notification. So, on iOS, I use the Firebase.analytics plugin without notifications. Hopefully, Rob will find out the problem and fix notifications soon. As for ANDROID, both notifications and firebase work perfectly for Android versions <8, but Firebase.analytics does NOT work on Android versions 8+.

The first key to having this work in certain cases was NOT to include the require(“plugin.notifications.v2”) definition in the code unless the platform is Android - iOS platform never includes the require.

The second key to having these plugins play nice, some of the time at least, is to make sure not to include the require(“plugin.firebaseAnalytics”) definition or run the firebase init code until at least 5 seconds after the notifications initialization occurs.

So, although it is odd to have such checks and dependencies between plugins, it’s the only thing I could do without waiting any longer - I just released my new game app today:  http://onelink.to/wpt53m and this game incorporates these odd dependencies properly.

So Rob, I’m still working with Scott (when he has time) to resolve the Firebase.analytics failure on Android v8+ - we sent him the cash to purchase an Android 8 phone, so that should be coming. The question is, what about the notifications crash? In view of Firebase’s here-to-stay liklihood, can CoronaLabs acquire Scott’s plugin and help him to fix the Android 8+ problem, too? It has already been a couple of weeks and he needs help IMHO.

btw, @GBFComm, keeping or removing the definition in my build.settings for iOS or Android makes no difference. The key is not to include the REQUIRE outside of a code routine. For example, function init_notifs() should have the require( definition of either plugin within the subroutine, so that Lua never attempts to init the plugin unless the code needing it asks for it. I hope this makes sense.

@Rob, it’s also important to understand that Google Ads and Google Play can incorporate data from Firebase, and for this reason, I’m arguing and begging CoronaLabs to see the importance of implementing GCM, which is also a free service like OneSignal, but will not likely ever have the same support issues I’ve faced with my app that has been crashing for several months on Android v8+ devices. Even with a Firebase update, since Scott’s code still doesn’t work on Android 8+, at least it is working for <8 for now. The point is, I’m asking for Corona to seriously look at the notifications solution that uses GCM and recognize the importance of either taking over Scott’s plugin (for some benefit) or creating a basic Firebase plugin that will at least report data to Firebase, even if it doesn’t retrieve data from it. I’m not sure that last sentence was completly accurate, as I don’t understand how to communicate with Firebase directly, yet.

Troy, GCM to me means Google Cloud Messaging. This is Google’s old push notification system. Google has deprecated GCM and is only supposed to be allowing Firebase Cloud Messaging (FCM) push notifications now. However I believe, due to the volume of GCM apps in the store, Google is having a hard time shutting that service down.

The original notifications plugin (v1) uses GCM. If you want to skip using FCM, you could try to drop back to the V1 of the notification plugin. It should be code compatible.

Now what I can’t say is if we have updated the notifications v1 plugin because we are under the assumption it’s been deprecated by Google. You could run into ANR and Crash problems in particular on Android 8 devices.

I can speak with Engineering about rebuilding the v1 plugin, but given that Google is discouraging people from using GCM, I’m not sure how much traction I can get.  We can’t just take Scott’s plugin from him. If he wants us to help, he can approach us about it and then we can look at options then.

We have multiple other analytics offerings that can track installs and app launching. What benefits does Firebase Analytics provide that our Google Analytics or GameAnalytics or any of our other options?

Rob

@Rob, thank you for your thoughtful reply, as always.

I was incorrect in my reference of GCM - I meant FCM, so my mistake.

I believe you are right about v1 of the notifications plugin, as it likely will crash just as oneSignal does.

So, is it safe to say that if I don’t include firebase.analytics within my app, the Firebase stream will still recognize each device because of the new v2 notifications plugin, and therefore, firebase.analytics is unnecssary in reporting data to Firebase? In other words, was I wrong to assume the firebase.analytics plugin was necessary to report the install and app startups?

The notification plugin’s job is to register the device with FCM. I’m not sure what you mean by the “Firebase stream”. What data are you reporting to firebase? 

If you want to track app installs and app startups, you probably need some form of analytics. The question is why do you feel Firebase needs to know this information.

Rob

Hy,

I have been facing the same problem, I have updated firebase to the latest version, but noticed that firebase Analytics was missing, I downgraded the firebase version and got Installing FirebaseAnalytics (5.2.0)

but when I run the app it crashes on 

[[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRMessagingAPNSTokenTypeSandbox];

I get the following error:

[FIRInstanceID setAPNSToken:type:]: unrecognized selector sent to instance 0x1c40bb960

Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: '-[FIRInstanceID setAPNSToken:type:]: unrecognized selector sent to instance 0x1c40bb960’

 

Knowing that this method is related to FirebaseAnalytics 

 

Any idea how I can make it work? I am using firebase to enable push notifications.

 

Thank you for your help.

Hello community,

I allow myself to post again because we still have not found an answer to our problem, and our client may lose patience.

We have downloaded the latest Corona daily build, updated Xcode and retried to build and the result is still the same.

Has Apple changed anything on its side with the upcoming arrival of iOS 12?

Has anyone encountered the same problem … and maybe found a solution? 

The problem does not seem to concern only our latest new application.

We tried to build again our old applications that worked perfectly until then (created on the same model) and we also meet the same problem.

Thank you very much for the help you can give me.

Can you put together a sample project that demonstrates the problem and use the Report a Bug feature at the top of the screen.

It needs to be a project that our engineers can build and run on a device, so provide a main.lua, config.lua, build.settings and other necessary files in a .zip file along with details on how to setup and run the project.

Thanks

Rob

I have been unable to release my new app due to this problem. I thought this was related to the firebase.analytics plugin, but after disabling that, the notification does exit the app immediate after bringing up the ALLOW or DISALLOW dialog. Imagine that the allow or disallow dialog comes up and then behind it, your app closes. Makes no sense.

FYI, I’m using build 3366 (3 versions newer from GBF Comm)

Hello Rob, Bektur, troylyndon and community!

We submitted the bug report with a sample code leaving only V2 notification and FirebaseAnalytics. We had a feedback saying to try without the Scott Harrison firebase Analytics plugin. We have indeed tried without this plugin and it works. No more crash! and the the ALLOW or DISALLOW dialog works.

So it looks like Scott Harrison’s Firebase Analytics plugin is causing the problem and crashing at notifications.registerForPushNotifications ({useFCM = true}).

We already had a problem of cohabitation of the two plugin. We understood that it was imperative to perform the initialization of Analytics firebase a few seconds after the call to notifications. So with a timer.performWithDelay everything worked until then.

Apparently this does not work anymore and we must now find how to succeed in making both plugins live together.

would anyone have an idea? do you know if scott Harrison is actively following the Corona forums?

This is two major plugin for Corona and the fact that it can no longer cohabit together is really a problem for us. :frowning: