Search Unity

Regarding UNITY_USES_REMOTE_NOTIFICATIONS and missing callbacks for push registration

Discussion in 'iOS and tvOS' started by BlaceX, Sep 5, 2016.

  1. BlaceX

    BlaceX

    Joined:
    Oct 28, 2015
    Posts:
    7
    There seem to be an issue with unity 5.4 building for Xcode when you are using remote push notifications. You can register for push notifications but the callbacks returning the push-token or error is never called. After a lot of digging around i found that there is a compiler tag in Xcode that are always false (0). The delegates in Xcode listening for the token/error callbacks are defined inside this compiler tag. Adding the compiler tag in the buildsettings in unity does not work. The only solution is to make a precompiler script or modefy the value directly in Xcode. This must be a bug in Unity or there might be missing an option somewhere to enable/disable this.

    The compiler tag: UNITY_USES_REMOTE_NOTIFICATIONS

    Results in missing callback for didRegisterForRemoteNotificationsWithDeviceToken, meaning the devicetoken will never be available in unity.

    I created this post mainly to help others with the issue and to ask Unity whats going on and if it is intended.

    Check this link for a post-process script. Thanks @adamt
    http://answers.unity3d.com/questions/1225564/enable-unity-uses-remote-notifications.html
     
    Last edited: Sep 8, 2016
    DoN2kcz, adamt and pinatti like this.
  2. pinatti

    pinatti

    Joined:
    Sep 5, 2016
    Posts:
    1
    @BlaceX You saved my day, your solution works like a charm!
     
    BlaceX likes this.
  3. adamt

    adamt

    Joined:
    Apr 1, 2014
    Posts:
    116
    You have got to be kidding me. I lost a day (and an evening!) on this issue, and your fix worked perfectly, @BlaceX. It drives me absolutely insane that Unity can fundamentally break an existing feature in a new release, with no documentation about the macro and its existence, nor apparently any unit tests to cover the change.

    For those of you struggling with this how to solve this problem, you might want to look at this Unity Answers thread for a working post-process script.
     
    BlaceX likes this.
  4. BlaceX

    BlaceX

    Joined:
    Oct 28, 2015
    Posts:
    7
    @adamt glad to help, I posted because I spend a lot of time on it as well and there were no posts with solutions linked to the problem. If you searched for anything specific when looking for the issue please write it here so it can be added to the post. It will make it easier for others to find the solution when they search for it. It was making me crazy that it was so hard to google because the issue was touching so many areas.
     
  5. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Is it worth submitting a bug report?
     
  6. adamt

    adamt

    Joined:
    Apr 1, 2014
    Posts:
    116
    I submitted one yesterday, but was told there is already one in-play. The sad part is that apparently this has been broken since beta 15 of 5.4, and Unity doesn't consider it a regression (how breaking an existing feature doesn't count as a regression is beyond me, but I'm not a QA engineer so I'll take their word for it), so the chance of it getting fixed, based on their new bug scoring system seems low.
     
  7. Omar_Unity

    Omar_Unity

    Unity Technologies

    Joined:
    Aug 30, 2016
    Posts:
    3
    That's a known bug which is being solved as you can see here:https://issuetracker.unity3d.com/is...de-project-when-notificationservices-are-used

    There is a simpler workaround that could help in the meantime:

    You must insert the following line before calling "RegisterForNotifications":

    Code (CSharp):
    1. var unused_var =typeof(UnityEngine.iOS.RemoteNotification);
    For example your MonoBehaviour's start function could look like this:

    Code (CSharp):
    1. voidStart(){
    2.      var unused_var =typeof(UnityEngine.iOS.RemoteNotification);
    3.      tokenSent =false;
    4.      NotificationServices.RegisterForNotifications(NotificationType.Alert|NotificationType.Badge|NotificationType.Sound,true);
    5. }
    The statement will change the value of the preprocessor directive "UNITY_USES_REMOTE_NOTIFICATIONS" from default 0 to 1, at "Preprocessor.h" in the trampoline Xcode project.

    Another way to do that is manually change the "#define UNITY_USES_REMOTE_NOTIFICATIONS" value to 1.

    I hope that helps!
     
  8. adamt

    adamt

    Joined:
    Apr 1, 2014
    Posts:
    116
    Thanks for the response and workaround, Omar.

    You linked to the same bug I'd already linked to in my post, so I'm wondering if you meant to link to another bug? Like I mentioned, that particular bug has been open since April, isn't marked as a regression, and doesn't have any comments from Unity about its current status. So from our perspective, a proper fix may never see the light of day (you could argue that a bug listed as "Active" means you're working on it, but 1.) that's not communicated anywhere in the issue tracker, and 2.) there are open bugs from 2014 that are also listed as active).

    Do you have a fix version for this particular bug? Maybe adding a new "In Progress" status to the issue tracker would give us better visibility into what's going to be fixed, as opposed to keeping our fingers crossed with every patch release.
     
  9. BlaceX

    BlaceX

    Joined:
    Oct 28, 2015
    Posts:
    7
    Thanks for the workaround. Adding that line of code works perfectly. No more manually changing the #define !

    I hope you will fix the issue because it can take some time to identify what is going on when you try to use push. And if there is something developers never have it is time !
     
  10. Omar_Unity

    Omar_Unity

    Unity Technologies

    Joined:
    Aug 30, 2016
    Posts:
    3
    Sorry for the delay! Well, right now it's hard to know an ETA or a milestone. What I can say is that I'll post here the answer as soon as I get it.
     
  11. ratmat2002

    ratmat2002

    Joined:
    Jun 13, 2014
    Posts:
    35
    This still seems to be broken in Unity 5.5.0p3 even with UNITY_USES_REMOTE_NOTIFICATIONS set to 1 and when trying the var unused_var =typeof(UnityEngine.iOS.RemoteNotification) hack.

    Anyone else having the same issue on Unity 5.5?
     
  12. bogdan-nevmerzytskiy

    bogdan-nevmerzytskiy

    Joined:
    Mar 18, 2015
    Posts:
    1
    Unity 5.5.0p3. also not work with hack UNITY_USES_REMOTE_NOTIFICATIONS
     
  13. egamestudio

    egamestudio

    Joined:
    Mar 11, 2016
    Posts:
    5
    I'm seeing the same issue using 5.5.2p4. Is there a work-around?