Not receiving push notifications on unity IOS while application is opened

0 votes

We are integrating push notifications in our game but we are facing this problem. If the game is backgrounded we receive those push notifications but not while opened. This is the method we are using for it:

void onPushNotificationsReceived(string pushMessageString)
    {
       
        Console.WriteLine("onPushNotificationsReceived....Called");
 
        if (pushMessageString.EndsWith("comprando"))
        {
            GameObject.Find("SaveGame").GetComponent<DataUpload>().Coroutines(5);
            PushActualizando();
        }
        else if (pushMessageString.EndsWith("actualizando"))
        {
            GameObject.Find("SaveGame").GetComponent<DataUploadAmigo>().DownloadD("OfertaDeObjetos");
        }
        else if (pushMessageString.EndsWith("visitando"))
        {
            string aux = "visitando";
            string personaAnadir = pushMessageString.Remove(pushMessageString.Length - aux.Length);
            lista.Add(personaAnadir);
 
        }
        else if (pushMessageString.EndsWith("saliendo"))
        {
            string aux = "saliendo";
            string personaQuitar = pushMessageString.Remove(pushMessageString.Length - aux.Length);
            lista.Remove(personaQuitar);
        }
 
        //dump you code here
        Debug.Log(pushMessageString);
    }
 
We think we are not entering this method because there is no message appearing on the Debug console.
 
Any kind of help would be mean so much. Thanks
asked Oct 14, 2016 in Unity by spotify17 (16 points)

1 Answer

+1 vote
 
Best answer

Hi,

It could be a case when "setListenerGameObject(this.gameObject.name);" is not called properly and hence listener is not set. You can also check "App42PushHandlerInternal.m" class in the xcode project under ios plugin. You can put logs in "app42RunTimeDidReceiveRemoteNotification" method of the above class to know if this method is called or not when you have received push while app is in foreground.

You can also share the complete xcode console logs in case this issue. It will help us to understand the problem you are facing.

Regards,

Rajeev Ranjan

answered Oct 17, 2016 by rajeev.etc (1,660 points)
selected Oct 17, 2016 by spotify17
Thanks for answering this fast. We have been trying what you said. The listener is called the sameway you do in the sample, we have debugged it and it is being passed correctly. We also have checked "App42PushHandlerInternal.m" putting logs in "app42RunTimeDidReceiveRemoteNotification" method but it is never called.

Here are the push logs from xcode:


Start called -----PushHandler
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
PushScript:Start()

Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

2016-10-17 14:49:09.857 winevillegame[1637:178283] setting=DidRegisterUserNotificationSettings successfully
2016-10-17 14:49:09.860 winevillegame[1637:178283] deviceToken=45a67cdd5da46c7318286353ed7a9b645e13bf281fd01342f3a253ece66cae3d
Estoy esperando Inventario
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
<DownloadData>c__Iterator42:MoveNext()

(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

settingDidRegisterUserNotificationSettings successfully
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
 
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

deviceToken45a67cdd5da46c7318286353ed7a9b645e13bf281fd01342f3a253ece66cae3d
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
PushScript:onDidRegisterForRemoteNotificationsWithDeviceToken(String)
 
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

registerDeviceTokenToApp42PushNotificationService   Called
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
PushScript:registerDeviceTokenToApp42PushNotificationService(String, String)
 
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

body{"app42":{"push":{"userName":"81e4f27f-df01-42f9-b9d6-6d20996ef5f5","deviceToken":"45a67cdd5da46c7318286353ed7a9b645e13bf281fd01342f3a253ece66cae3d","type":"iOS"}}}timeStamp2016-10-17T12:49:09.937Zversion1.0
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.util.Util:SortAndConvertTableToString(Dictionary`2)
com.shephertz.app42.paas.sdk.csharp.util.Util:Sign(String, Dictionary`2)
com.shephertz.app42.paas.sdk.csharp.pushNotification.PushNotificationService:StoreDeviceToken(String, String, String, App42CallBack)
PushScript:registerDeviceTokenToApp42PushNotificationService(String, String)
 
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

 GetInstance Not Null
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:GetInstance()
com.shephertz.app42.paas.sdk.csharp.pushNotification.PushNotificationService:StoreDeviceToken(String, String, String, App42CallBack)
PushScript:registerDeviceTokenToApp42PushNotificationService(String, String)
 
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

 QueryString is ?
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:ExecutePost(String, Dictionary`2, String, Dictionary`2, Dictionary`2, App42CallBack)
com.shephertz.app42.paas.sdk.csharp.pushNotification.PushNotificationService:StoreDeviceToken(String, String, String, App42CallBack)
PushScript:registerDeviceTokenToApp42PushNotificationService(String, String)
 
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

POST URI : https://api.shephertz.com/cloud/1.0/push/storeDeviceToken/81e4f27f-df01-42f9-b9d6-6d20996ef5f5?
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:ExecutePost(String, Dictionary`2, String, Dictionary`2, Dictionary`2, App42CallBack)
com.shephertz.app42.paas.sdk.csharp.pushNotification.PushNotificationService:StoreDeviceToken(String, String, String, App42CallBack)
PushScript:registerDeviceTokenToApp42PushNotificationService(String, String)
 
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

Waiting For Response...
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.connection.<WaitForRequest>d__3:MoveNext()
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:ExecutePost(String, Dictionary`2, String, Dictionary`2, Dictionary`2, App42CallBack)
com.shephertz.app42.paas.sdk.csharp.pushNotification.PushNotificationService:StoreDeviceToken(String, String, String, App42CallBack)
PushScript:registerDeviceTokenToApp42PushNotificationService(String, String)


 Success Value : {"app42":{"response":{"success":true,"push":{"userName":"cb7ad74b-d86b-4e7b-896e-33bfe48e3c1f","type":"iOS","deviceToken":"45a67cdd5da46c7318286353ed7a9b645e13bf281fd01342f3a253ece66cae3d"}}}}
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.connection.<Execute>d__6:MoveNext()
com.shephertz.app42.paas.sdk.csharp.connection.<WaitForRequest>d__3:MoveNext()
 
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

buildResponseForObjectService resource: push
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:BuildResponseForObjectService(String, App42CallBack, String)
com.shephertz.app42.paas.sdk.csharp.connection.<Execute>d__6:MoveNext()
com.shephertz.app42.paas.sdk.csharp.connection.<WaitForRequest>d__3:MoveNext()
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

UserName : cb7ad74b-d86b-4e7b-896e-33bfe48e3c1f
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
PushResponse:OnSuccess(Object)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:BuildResponseForObjectService(String, App42CallBack, String)
com.shephertz.app42.paas.sdk.csharp.connection.<Execute>d__6:MoveNext()
com.shephertz.app42.paas.sdk.csharp.connection.<WaitForRequest>d__3:MoveNext()
 
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

Expiery : 01/01/0001 00:00:00
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
PushResponse:OnSuccess(Object)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:BuildResponseForObjectService(String, App42CallBack, String)
com.shephertz.app42.paas.sdk.csharp.connection.<Execute>d__6:MoveNext()
com.shephertz.app42.paas.sdk.csharp.connection.<WaitForRequest>d__3:MoveNext()
 
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

DeviceToken : 45a67cdd5da46c7318286353ed7a9b645e13bf281fd01342f3a253ece66cae3d
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
PushResponse:OnSuccess(Object)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:BuildResponseForObjectService(String, App42CallBack, String)
com.shephertz.app42.paas.sdk.csharp.connection.<Execute>d__6:MoveNext()
com.shephertz.app42.paas.sdk.csharp.connection.<WaitForRequest>d__3:MoveNext()
 
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

pushNotification :
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
PushResponse:OnSuccess(Object)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:BuildResponseForObjectService(String, App42CallBack, String)
com.shephertz.app42.paas.sdk.csharp.connection.<Execute>d__6:MoveNext()
com.shephertz.app42.paas.sdk.csharp.connection.<WaitForRequest>d__3:MoveNext()
 
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

pushNotification : {"app42":{"response":{"success":true,"push":{"userName":"cb7ad74b-d86b-4e7b-896e-33bfe48e3c1f","type":"iOS","deviceToken":"45a67cdd5da46c7318286353ed7a9b645e13bf281fd01342f3a253ece66cae3d"}}}}
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
PushResponse:OnSuccess(Object)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:BuildResponseForObjectService(String, App42CallBack, String)
com.shephertz.app42.paas.sdk.csharp.connection.<Execute>d__6:MoveNext()
com.shephertz.app42.paas.sdk.csharp.connection.<WaitForRequest>d__3:MoveNext()
 
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

pushNotification : -1
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
PushResponse:OnSuccess(Object)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:BuildResponseForObjectService(String, App42CallBack, String)
com.shephertz.app42.paas.sdk.csharp.connection.<Execute>d__6:MoveNext()
com.shephertz.app42.paas.sdk.csharp.connection.<WaitForRequest>d__3:MoveNext()
 
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

pushNotification : iOS
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
PushResponse:OnSuccess(Object)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:BuildResponseForObjectService(String, App42CallBack, String)
com.shephertz.app42.paas.sdk.csharp.connection.<Execute>d__6:MoveNext()
com.shephertz.app42.paas.sdk.csharp.connection.<WaitForRequest>d__3:MoveNext()
 
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
Thanks for sharing the logs.
Is our sample working at your end? I have tested the sample provided by us and it is working fine with Unity version 5.4.0f3. Could you please share your sample project in which this is not working so that I can debug the same in that project itself. Also, please let me know the unity version with which you are working.
We are using the scripts that are in this sample: https://github.com/shephertz/App42iOSUnity3DPushPlugin

We have tested the sample and it is happening the same as before.
I don't know if this has anything to do with the problem but we are sending those pushes from ap42 cloud api while testing

Our Unity version is 5.3.4f1
Can you add me(collaborator@shephertz.com) as collaborator to your app from AppHQ Management Console? It will help us to debug the problem.

P.S. To add collaborator, please login to AppHQ -> AppManager -> Select Collaborator -> Click on Add Collaborator.
You have already been added as collaborator
What is your app name in AppHQ?
WineVilleGame
Can you send push notification from AppHQ management console to test the scenario you are facing? I am observing your app now. Let me know the result that you got the notification or not.
Okay, sorry for not realizing that you had answered us earlier. We are ready to send a push notification. Do we go for it?
sure, you can send the notification now.
We have done 2 pushes, the first one with the app in foreground, it didn´t appear in the xcode logs, the second one with the app in background, it appeared the notification and we could open the game from it.
Is it possible that you can test the sample provided by us on Unity with version 5.4.0f3 as it is working fine at my end with this version of unity. I will also try to test the sample with your version of unity at my end. I will update you as soon as I will complete my testing.
We have tested it on 5.4.0f3 and it is working perfectly. So it had to do with the unity version. Thank you for the help
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...