Problem integrating unity IOS PushNotifications

0 votes

Hi I have been trying to integrate shephertz push notification services into my game and have been unsuccessful in doing so. I read through the following link

http://blogs.shephertz.com/2013/08/08/steps-to-integrate-push-notification-with-unity3d-on-ios/ 

and followed the steps.

First of all i would like to point out that your sample on git hub for Unity Ios push notification does not work on Unity 5.2.

So i dragged the files “App42PushHandlerInternal.h/.m” classes to “Assets/Plugins/iOS” folder in my project and the scripts PushScript and PushResponse to my assets folder.

Added the PushScript to an empty game object.

Set the correct API and Secret Key.

Set the user name as the facebook userId.

When I built and ran the project in XCode I got a prompt that the app wants to send notifications. I clicked ok.

I logged in through facebook but after that this is all I could see in the log related to the push notification.

2015-10-16 16:36:39.645 wordrow[4355:3225422] deviceToken=b4cbaf908ce0b3492154120d0cb9cc918c4a34033c06e04797f40752335e4790
2015-10-16 16:36:39.646 wordrow[4355:3225422] setting=DidRegisterUserNotificationSettings successfully
SendMessage: object  not found!
SendMessage: object  not found!
 
Start called -----PushManager
Facebook.Unity.CallbackManager:CallCallback(Object, IResult)
Facebook.Unity.CallbackManager:OnFacebookResponse(IInternalResult)
 
and nothing else. Don't know how or what to do.
 
So it would be great if you could provide me with some better resources that will help with the push notifications.

 

 

 

 

 

closed with the note: Issue Resolved
asked Oct 16, 2015 in App42PaaS & BPaaS by jibran (10 points)
closed Oct 17, 2015 by jibran
could we talk on skype or phone?

1 Answer

0 votes

Hello Jibran,

Can you try calling following method just after setting the listener in PusgScript.cs? For example:

setListenerGameObject(this.gameObject.name);

registerForRemoteNotifications();

Let me know if the problem continues.

Thanks.

answered Oct 16, 2015 by rajeev.etc (1,660 points)
they have already been called in the PushScript? Isnt it?
thats where Start called -----PushManager comes from
Can you share the PushScript.cs script?
I believe that "setListenerGameObject" is called already but "registerForRemoteNotifications" is not called.

Let me know if this is not the case and please share the PushScript.cs. It will help to debug the problem.
using UnityEngine;
using System.Collections;
using com.shephertz.app42.paas.sdk.csharp;
using com.shephertz.app42.paas.sdk.csharp.pushNotification;
using System;
using System.Runtime.InteropServices;

public class PushScript : MonoBehaviour
{
    const string api_key = "Your_API_Key";
    const string secret_key = "Your_Secret_Key";
   
    PushResponse callBack = new PushResponse();
    [System.Runtime.InteropServices.DllImport("__Internal")]
    extern static public void registerForRemoteNotifications();
   
    [System.Runtime.InteropServices.DllImport("__Internal")]
    extern static public void setListenerGameObject(string listenerName);
   
    // Use this for initialization
    void Start ()
    {
        App42Log.SetDebug(true);
        Debug.Log("Start called -----"+this.gameObject.name);
        setListenerGameObject(this.gameObject.name);// sets the name of the game object as a listener to which this script is assigned.
    }
   
    //Sent when the application successfully registered with Apple Push Notification Service (APNS).
    void onDidRegisterForRemoteNotificationsWithDeviceToken(string deviceToken)
    {
        Debug.Log("deviceToken"+deviceToken);
        if (deviceToken != null && deviceToken.Length!=0)
        {
            registerDeviceTokenToApp42PushNotificationService(deviceToken,"User Name");
        }
    }
   
    //Sent when the application failed to be registered with Apple Push Notification Service (APNS).
    void onDidFailToRegisterForRemoteNotificcallBackationsWithError(string error)
    {
        Debug.Log(error);
    }
   
    //Sent when the application Receives a push notification
    void onPushNotificationsReceived(string pushMessageString)
    {
        Console.WriteLine("onPushNotificationsReceived....Called");
        //dump you code here
        Debug.Log(pushMessageString);
    }
   
    //Registers a user with the given device token to APP42 push notification service
    void registerDeviceTokenToApp42PushNotificationService(string devToken,string userName)
    {
        Debug.Log("registerDeviceTokenToApp42PushNotificationService   Called");
        ServiceAPI serviceAPI = new ServiceAPI(api_key,secret_key);   
        PushNotificationService pushService = serviceAPI.BuildPushNotificationService();
        pushService.StoreDeviceToken(userName,devToken,"iOS",callBack);
        //pushService.StoreDeviceToken(userName,devToken,com.shephertz.app42.paas.sdk.csharp.pushNotification.DeviceType.iOS);
    }

       
    //Sends push to a given user
    void SendPushToUser(string userName,string message)
    {
        Debug.Log("SendPushToUser Called");
        ServiceAPI serviceAPI = new ServiceAPI(api_key,secret_key);   
        PushNotificationService pushService = serviceAPI.BuildPushNotificationService();
        pushService.SendPushMessageToUser(userName,message,callBack);
       
    }

    void onDidRegisterUserNotificationSettings(string setting)
    {
        Debug.Log("setting"+setting);
    }
   
}
when and where shall i call it?
Replace the start method of the script with following and try:

    void Start ()
    {
        App42Log.SetDebug(true);
        Debug.Log("Start called -----"+this.gameObject.name);
        setListenerGameObject(this.gameObject.name);
        registerForRemoteNotifications();
    }

Let me know if the problem continues.
Well it worked partially. I can see success callbacks in the log. I can see the user is added to the the AppHQ dashboard under push users but i dont receive any notifications on my phone. What could be the issue?
Can you share the response logs you got from the server, when you sent push? Which API you are using to send the notification? Also, can you try sending push from AppHQ Console to the user and share the Push Logs? To see the push logs, please go to Unified Notification->Push->Logs.

P.S.:- You also need to enable the push logs from app settings in AppManager before sending push if not enabled already.
I sent the push using dashboard too but the result was same. I can see the user added to the push user but in the logs menu it shows "No push logs found"
"iOS KeystoreException  : Invalid keystore password!  Verify settings for connecting to Apple..." This is what i get in the app hq push log
its working now. Thanx 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
...