Search Unity

Unity 3.5 and Push Notifications

Discussion in 'iOS and tvOS' started by Luke-Kellett, Feb 24, 2012.

  1. Luke-Kellett

    Luke-Kellett

    Joined:
    Oct 22, 2011
    Posts:
    9
    Hey Guys,

    So I've recently upgraded to 3.5 from 3.4 where I was using the Prime31 Etcetera push notification functions.

    They allowed for easy registration for push, and for notifications to be sent via events. But it looks like the new version of Unity does the registration and then expects the user to poll for the push token and also notifictions even though it is consuming the iOS events in ObjC.


    Does anyone know if this is the case or if there are in fact events I can trap for the push token and receiving events?


    Unity 3.5 Example
    Code (csharp):
    1.  
    2. function Start() {
    3.     NotificationServices.RegisterForRemoteNotificationTypes(RemoteNotificationType.Alert |
    4.                                 RemoteNotificationType.Badge |
    5.                                 RemoteNotificationType.Sound);
    6. }
    7.  
    8. function Update () {
    9.     if (!tokenSent) {
    10.         var token : byte[] = NotificationServices.deviceToken;
    11.         if (token != null) {
    12.             // send token to a provider
    13.             var hexToken : String = "%" + System.BitConverter.ToString(token).Replace('-', '%');
    14.             new WWW("http://"+address+"/?token="+hexToken);
    15.             tokenSent = true;
    16.         }
    17.     }
    18. }
    19.  
     
  2. esvaldo

    esvaldo

    Joined:
    Dec 11, 2009
    Posts:
    52
    I'm also interested on this. Have you found a solution?

    At the moment I use Prime31 plugin to integrate the UrbanAirship service, but I would like to implement the service from Appoxee (http://appoxee.com) using Unity native API.

    Has anyone tried this?
     
  3. Luke-Kellett

    Luke-Kellett

    Joined:
    Oct 22, 2011
    Posts:
    9
    I've actually had to go with polling unfortunately... What this means is the edge case of a user receiving a push notification while in app/game is that if they have < iOS 5 it wont actually show

    What I am doing is using a script with a OnApplicationPause() and Start() method to check for notifications and then act on them, not perfect but gets the job done.

    On a side note, only 20% of my user base actually allows push notifications so it's not high priority thing for me. If you are looking at Appoxee for more than push notifications I suggest you also take a look at PlayHaven or Applifier as they are much more mature services with more features.
     
  4. normantran86

    normantran86

    Joined:
    Nov 15, 2010
    Posts:
    29
    Is this why didReceiveRemoteNotification in the Objective C AppControllersPushAdditions.mm is disabled for Unity 3.5? How do I receive the Push Notification payload?
     
  5. Luke-Kellett

    Luke-Kellett

    Joined:
    Oct 22, 2011
    Posts:
    9
    On the Unity code side of things you need to use the NotificationServices object which allows you to get the data... Unfortunately you need to check for notifications on Start and OnApplicationPause to get the data. No events exist in Unity for this :-(
     
  6. normantran86

    normantran86

    Joined:
    Nov 15, 2010
    Posts:
    29
    Well I mean... if I just move the #if UNITY_3_5 down a function then etceteramanager will fire off those events and I don't have to use NotificationServices. Did prime31 disable this for some reason?
     
  7. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @normantran, I just pushed out an update that will use both the Unity 3.5 method and fire the event. I didn't realize Unity's NotificationServices didnt have events and it pains me to see folks coding up needless polling...
     
    Last edited: Mar 20, 2012
  8. Luke-Kellett

    Luke-Kellett

    Joined:
    Oct 22, 2011
    Posts:
    9
    @Prime31 Nice one!

    From Unity's response to my support call, it looks like they have no plan for firing events themselves either...
     
  9. normantran86

    normantran86

    Joined:
    Nov 15, 2010
    Posts:
    29
    Is the plugin working for the 5.1 sdk? My coworker is building to devices with the new sdk but they are not registering for the remote notifications nor are they receiving the device token. Whereas when I build with teh 5.0 sdk, the devices get the device token.
     
  10. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @norman, assuming you have Unity 3.5 and the latest version of the plugin it should work fine. If you are in an older version of Unity visit the docs page for the required compatibility change. And of course make sure you are using a push enabled provisioning profile.
     
  11. Jason.d

    Jason.d

    Joined:
    Apr 1, 2012
    Posts:
    1
    Regarding other push notification services; I've been using Appoxee for a while and they're super great!
    I've also upgraded to their Pro edition to get direct support and their API for tagging.

    I suggest you re-consider the service
     
  12. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
  13. Russel

    Russel

    Joined:
    Oct 12, 2011
    Posts:
    40
    Is there this tutorial somewhere or can you send it to me?
     
  14. CarlosFM

    CarlosFM

    Joined:
    Jun 8, 2013
    Posts:
    240
    @Russel: I've recently submitted a cross-platform notification system to the Unity Asset Store that might help you setting up your own Remote Notifications in android and in iOS. It comes with all you will need to do it -code, examples and a full step-by-step guide to help on the most scary parts of the process (such as permissions, certificates, etc.)

    http://forum.unity3d.com/threads/185452-Easy-Cross-Platform-Notifications-available-now!

    http://u3d.as/content/carlos-fernandez-musoles/easy-cross-platform-notifications/

    Hope it helps!

    Carlos.
     
  15. ajayaec

    ajayaec

    Joined:
    Jul 31, 2013
    Posts:
    4
  16. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    why don't you guys do a rest api for device registration?
    I don't understand why the compiled libraries, dll, and android specific stuff. Some of us already have push notification on our system set up, so all we want is to switch service.

    A simple WWW(url) with params to do "registerDevice?apiKey&myuser&whatevertag" would be great. i do it with pushwoosh and it works fine.

    Then I let each platform to handle the push notifications with their standard system.