Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by fox · Sep 14, 2017 at 06:27 PM · unity 5iosxcodebuildpipeline

Create "Notification Service Extension" from post build script

Hi! We are using a postbuild-script to modify our xcode project.

Works great, but now we need your help. We are trying to add a "Notification Service Extension"-target from code (see picture). Picture

We can add a new xcode target by using PBXProject.AddAppExtension, but with this we only get a "normal" target, not a specific "Notification Service Extension"-template-one..

Reason why we want this done by code is that we are trying to get OneSignal to work with Unity Cloud Build. We have step 1 ready and working from our script, but struggling with the second part in the setup guide found here: https://documentation.onesignal.com/docs/unity-sdk-setup

Any input would be very nice. Thanks!

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image andersemil · Oct 07, 2017 at 08:07 AM 0
Share

@fox Were you ever able to find a solution? I can't even find the AddAppExtension method on PBXProject. According to the docs, this is only available in 2017.1 but your post is tagged with Unity 5? Completely lost.

avatar image fox andersemil · Oct 11, 2017 at 07:32 AM 0
Share

Hi! Sorry for late answer. That Unity 5 tag was a mistake, it should be Unity 2017.1. And we havent found a solution yet. Working on it, will keep you updated. Have you tried? Any luck?

avatar image andersemil fox · Oct 11, 2017 at 08:13 AM 0
Share

I'm in the process of upgrading to 2017.1.1 to see if I can make it work. We were still on unity 5.6.3 because we saw many graphics glitches in our 2D game when upgrading to 2017.1, hope they have fixed it now in 2017.1.1.

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by andersemil · Oct 11, 2017 at 10:14 AM

The type of extension is determined by the NSExtensionPointIdentifier entry in your extension's Info.plist. I managed to automate the creation of a notification service extension target and setting of all the annoying things that need to be set. Below is the code I'm using

     [PostProcessBuild]
     public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
     {
         if(target == BuildTarget.iOS)
         {
             var projPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);
             PBXProject proj = new PBXProject ();
             proj.ReadFromFile (projPath);
             string targetGUID = proj.TargetGuidByName ("Unity-iPhone");
 
             var plistPath = pathToBuiltProject + "/Info.plist";
             PlistDocument plist = new PlistDocument();
             plist.ReadFromFile (plistPath);
 
             var pathToNotificationService = /* PATH TO YOUR NOTIFICATION SERVICE SOURCEFILES */;
             var notificationServicePlistPath = pathToNotificationService + "/Info.plist";
             PlistDocument notificationServicePlist = new PlistDocument();
             notificationServicePlist.ReadFromFile (notificationServicePlistPath);
             notificationServicePlist.root.SetString ("CFBundleShortVersionString", PlayerSettings.bundleVersion);
             notificationServicePlist.root.SetString ("CFBundleVersion", PlayerSettings.iOS.buildNumber.ToString ());
             var notificationServiceTarget = PBXProjectExtensions.AddAppExtension (proj, targetGUID, "notificationservice", PlayerSettings.GetApplicationIdentifier (BuildTargetGroup.iOS) + ".notificationservice", notificationServicePlistPath);
             proj.AddFileToBuild (notificationServiceTarget, proj.AddFile (pathToNotificationService + "/NotificationService.h", "NotificationService/NotificationService.h"));
             proj.AddFileToBuild (notificationServiceTarget, proj.AddFile (pathToNotificationService + "/NotificationService.m", "NotificationService/NotificationService.m"));
             proj.AddFrameworkToProject (notificationServiceTarget, "NotificationCenter.framework", true);
             proj.AddFrameworkToProject (notificationServiceTarget, "UserNotifications.framework", true);
             proj.SetBuildProperty (notificationServiceTarget, "ARCHS", "$(ARCHS_STANDARD)");
             proj.SetBuildProperty (notificationServiceTarget, "DEVELOPMENT_TEAM", PlayerSettings.iOS.appleDeveloperTeamID);
             notificationServicePlist.WriteToFile (notificationServicePlistPath);
 
             proj.WriteToFile (projPath);
             plist.WriteToFile (plistPath);
         }
     }
 
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ashwin_dinesh · May 07, 2019 at 09:45 AM 0
Share

I tried this code snippet in Unity 2018, it creates a Notification Service Extension, but it did not work. Whereas when I create the same extension from Xcode, it works perfectly. Could you please confirm that this works with Unity 2018 and Xcode 10.

avatar image andersemil ashwin_dinesh · May 07, 2019 at 10:28 AM 0
Share

Again, this code snippet does not create the extension, it merely includes the extension in the Unity Xcode project and sets up the target. We use this exact same code with Unity 2018 and Xcode 10 today.

avatar image ashwin_dinesh andersemil · May 07, 2019 at 01:10 PM 0
Share

What do you mean by merely including the extension? I have added correct Info.plist and source files to this code, what else have you done to get a fully working extension?

avatar image
0

Answer by ashwin_dinesh · May 06, 2019 at 01:36 PM

Where are you setting value for NSExtensionPointIdentifier?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image andersemil · May 06, 2019 at 01:58 PM 0
Share

You need to create the service from template in Xcode first and then link to it using my example above.

Btw, you've posted your comment as an answer, you should have clicked "Add comment" ins$$anonymous$$d ;) for next time.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

167 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

iOs Build and run does not automatically run the game 1 Answer

ios changes aren't showing when running app 0 Answers

Accessing the volume buttons on iPhone for some functionality through Unity 1 Answer

unity 5 u3dxt xCode errors 0 Answers

ArKit not included in unity.framework on xcode 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges