Plugin error - attempt to concatenate field 'token' (a nil value)

Just decided to try GameThrive. 

First impression is really great. Very good documentation and very easy step-by-step set up.

When I installed my iOS app and noticed in the console the following error:

May 24 18:29:53 Renatos-iPhone MyApp[8022] \<Warning\>: Runtime error /Users/hiptic/Documents/GameThrive/SDK/Corona/SDK/shared/plugin\_GameThrivePushNotifications.lua:292: attempt to concatenate field 'token' (a nil value) stack traceback: /Users/hiptic/Documents/GameThrive/SDK/Corona/SDK/shared/plugin\_GameThrivePushNotifications.lua:292: in function \</Users/hiptic/Documents/GameThrive/SDK/Corona/SDK/shared/plugin\_GameThrivePushNotifications.lua:270\> ?: in function \<?:218\>

I imagine that occurred because my app didn’t receive the device token (when I started the app I didn’t receive the Push Permission Alert, so I already suspected that the app was not correctly registered).

Anyway, I think it is something that you guys want to double check.

This Push Permission Alert thing is very confusing. I had an app in development and it was using another push provider. When I moved it over to GameThrive I didn’t get the Push Permission Alert either. I was still getting the notifications from GameThrive though so for all intent and purposes it was working well. Then recently my IOS Dev certs expired so I had to redo the whole lot. Guess what, first time I reinstalled my app after generating the new certs I was asked for the Push Permission. So it seems like a device retains your choice for a given app even if the push provider changes. Hope this helps.

Thanks ksan. The problem of the app not receiving the Push Permission request was something on my side, I didn’t doubt that.

In my case, I simply created a new Provising Profile on Apple portal and installed on my machine (I was using before the xCode Managed profile) and it solved.

I just think that the GameThrive people want to double check that error, because it appears that they are not checking if the token exist before concatenating it with other string. Perhaps that line is just the print that they do of the token to the console, but anyway, it is good to not have errors inside the code.

I agree. This should be checked and protected against. 

Quick question. Do you know which GameThrive action is causing this? I had a similar problem where I was trying to tag user right inside main.lua, right after initial GT setup. In that case the user registration was not coming through soon enough. If I reran the same code second time the error was going away since the user by then was already registered. Can it be something like that?

Answer was either to run the tagging later on or with delay or better yet, use the GameThrive.IdsAvailableCallback() API to make sure the registration is there. Just an idea. 

 local function gamethriveCallback() isConnected = true deliverTags() end GameThrive.IdsAvailableCallback(gamethriveCallback)

In my case, the token was not received because some problem during the build (that was done without the APNS). With the new Provision Profile, I stated to receive the Permission Request.

The problem that I reported on the first post was happening after the start. I see that they print the user token to the console, so I am guessing that they problem maybe with print command. They should be using 

print("Registering player with event.token: ".. event.token) 

what causes error when the event.token is nil. A safer way is to use:

print("Registering player with event.token: ", event.token)

In my case the app didn’t crash, but I don’t know if the error could stop the function to continue running and then your callback is not called.

By the way, you that callback was exactly the function that I was looking for here! thanks!

Super! Glad to be of help. George from GT was the person who pointed out to that callback to me and it has worked great so far. 

I agree with you on the need to get rid of that error though. I’m sure GT will get to it. They are super responsive.

Thanks for the bug report and good suggestion on preventing that error! Glad you were able to find the source of the problem. We’ll explore what we can do handle this error case better.

This Push Permission Alert thing is very confusing. I had an app in development and it was using another push provider. When I moved it over to GameThrive I didn’t get the Push Permission Alert either. I was still getting the notifications from GameThrive though so for all intent and purposes it was working well. Then recently my IOS Dev certs expired so I had to redo the whole lot. Guess what, first time I reinstalled my app after generating the new certs I was asked for the Push Permission. So it seems like a device retains your choice for a given app even if the push provider changes. Hope this helps.

Thanks ksan. The problem of the app not receiving the Push Permission request was something on my side, I didn’t doubt that.

In my case, I simply created a new Provising Profile on Apple portal and installed on my machine (I was using before the xCode Managed profile) and it solved.

I just think that the GameThrive people want to double check that error, because it appears that they are not checking if the token exist before concatenating it with other string. Perhaps that line is just the print that they do of the token to the console, but anyway, it is good to not have errors inside the code.

I agree. This should be checked and protected against. 

Quick question. Do you know which GameThrive action is causing this? I had a similar problem where I was trying to tag user right inside main.lua, right after initial GT setup. In that case the user registration was not coming through soon enough. If I reran the same code second time the error was going away since the user by then was already registered. Can it be something like that?

Answer was either to run the tagging later on or with delay or better yet, use the GameThrive.IdsAvailableCallback() API to make sure the registration is there. Just an idea. 

 local function gamethriveCallback() isConnected = true deliverTags() end GameThrive.IdsAvailableCallback(gamethriveCallback)

In my case, the token was not received because some problem during the build (that was done without the APNS). With the new Provision Profile, I stated to receive the Permission Request.

The problem that I reported on the first post was happening after the start. I see that they print the user token to the console, so I am guessing that they problem maybe with print command. They should be using 

print("Registering player with event.token: ".. event.token) 

what causes error when the event.token is nil. A safer way is to use:

print("Registering player with event.token: ", event.token)

In my case the app didn’t crash, but I don’t know if the error could stop the function to continue running and then your callback is not called.

By the way, you that callback was exactly the function that I was looking for here! thanks!

Super! Glad to be of help. George from GT was the person who pointed out to that callback to me and it has worked great so far. 

I agree with you on the need to get rid of that error though. I’m sure GT will get to it. They are super responsive.

Thanks for the bug report and good suggestion on preventing that error! Glad you were able to find the source of the problem. We’ll explore what we can do handle this error case better.