Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

How do I enable Remote Push Notification Capability using Unity Cloud Build?

Discussion in 'iOS and tvOS' started by DrakenDev, Feb 23, 2017.

  1. DrakenDev

    DrakenDev

    Joined:
    Jul 20, 2012
    Posts:
    11
    Hi, I've been struggling on and off for a few weeks now to get Push Notifications working for my Unity Game.
    I always get the following message when trying to submit my IPA file.
    I think the issues is I need to enable Capabilities>Background Modes>Remote Notifications.

    And I've tried doing this by adding the following into the info.plist. Which appears to not do anything
    Code (csharp):
    1.                 <key>UIBackgroundModes</key>
    2.                 <array>
    3.                     <string>remote-notification</string>
    4.                 </array>
    The thing is, I'm using Unity Cloud Build for everything and have no-idea how this is meant to work for that. I've done extensive Googling and cannot come up with ANYTHING. It's really surprising me that in my search no-one has come up against this issue... I really need help...

    Thanks in advance!
     
    Last edited: Feb 23, 2017
    tonybf and unity_lPMFtIfNA_qPBA like this.
  2. DrakenDev

    DrakenDev

    Joined:
    Jul 20, 2012
    Posts:
    11
  3. lindsaytalbot

    lindsaytalbot

    Joined:
    Sep 11, 2015
    Posts:
    28
    Having similar problem but with iCloud. Suspect whatever solution you get will also help with mine
     
  4. QuantumCalzone

    QuantumCalzone

    Joined:
    Jan 9, 2010
    Posts:
    259
    Got push notifications to work in UCB via this post might help with other capabilities
     
  5. DrakenDev

    DrakenDev

    Joined:
    Jul 20, 2012
    Posts:
    11
    YEP! THAT WORKED!
    I skipped the part about XCode and creating an entitlements file. I just put the contents of my "AppName.Entitlements" file as
    Code (csharp):
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    3. <plist version="1.0">
    4.   <dict>
    5.     <key>aps-environment</key>
    6.     <string>production</string>
    7.   </dict>
    8. </plist>
    Pointed the .UnityPackage at the file, commited to Unity Cloud Build and after uploading to Apple, voila! It worked!
     
    a_p_u_r_o likes this.
  6. ashwin_dinesh

    ashwin_dinesh

    Joined:
    Feb 21, 2019
    Posts:
    3
    This is how you can add background-modes through post-process-build script:

    Code (CSharp):
    1.  
    2. PBXProject proj = new PBXProject();
    3. string projPath = PBXProject.GetPBXProjectPath(buildPath);
    4. proj.ReadFromFile(projPath);
    5.  
    6. string targetName = PBXProject.GetUnityTargetName();
    7. string mainTarget = proj.TargetGuidByName(targetName);
    8.  
    9. // Enable background mode
    10. proj.AddCapability(mainTarget, PBXCapabilityType.BackgroundModes);
    11.  
    12. proj.WriteToFile(projPath);
    13. File.WriteAllText(projPath, proj.WriteToString());
    14.  
    15. // Add background modes
    16. string plistPath = buildPath + "/Info.plist";
    17. PlistDocument plist = new PlistDocument();
    18. plist.ReadFromString(File.ReadAllText(plistPath));
    19. PlistElementDict rootDict = plist.root;
    20. PlistElementArray arr = rootDict.CreateArray("UIBackgroundModes");
    21. arr.AddString("remote-notification");
    22. arr.AddString("fetch");
    23. File.WriteAllText(plistPath, plist.WriteToString());
    24.  
     
  7. studentutu

    studentutu

    Joined:
    Oct 22, 2017
    Posts:
    88
    Just don't forget :
    Push notification entitile value is choosen from Xcode - when in simple test build it will give you either development or production value!
    Also, don't forget to check if the frameworks are linked! (Xcode API is old so it does'nt know about new Xcode!)
     
  8. David_132

    David_132

    Joined:
    Dec 14, 2018
    Posts:
    6
    We are using a third party Scalefusion iOS MDM for remote push notification.
     
  9. resilio

    resilio

    Joined:
    Sep 7, 2017
    Posts:
    12
    If anyone already uses `ProjectCapabilityManager`, one can simply add these lines:

    Code (CSharp):
    1.  
    2. var capManager = new ProjectCapabilityManager(projPath, entitlementsPath, "Unity-iPhone");
    3. capManager.AddBackgroundModes(BackgroundModesOptions.BackgroundFetch);    capManager.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications);
    4. capManager.WriteToFile();
    5.  
     
    tonybf likes this.
  10. adrian_bp

    adrian_bp

    Joined:
    Nov 25, 2019
    Posts:
    1
    Where did you get the entitlementsPath? did you need to create an empty file?
     
  11. k_belonogov

    k_belonogov

    Joined:
    Jan 12, 2016
    Posts:
    2
    var entitlementsFileName = pbxProject.GetBuildPropertyForAnyConfig(mainTarget, "CODE_SIGN_ENTITLEMENTS") ?? Application.identifier + ".entitlements";

    var capManager = new ProjectCapabilityManager(projPath, entitlementsFileName, "Unity-iPhone");
     
    Last edited: Aug 25, 2020
unityunity