Saturday, November 16, 2024
HomeiOS Developmentios - SOLVED: Easy methods to add App Capabilities resembling Push Notifications...

ios – SOLVED: Easy methods to add App Capabilities resembling Push Notifications + Background Mode to Xcode automated from command line / for Unity

[ad_1]

I wished so as to add App Capabilities in an automatic vogue with out having to make use of the person interface to click on via. One thing that I may use for construct automation.

There are a number of methods to change an Xcode undertaking to incorporate App capabilities resembling Push Notification or Background Modes. Whenever you use a growth framework, resembling Unity, ideally, the framework or a plugin will do the mandatory give you the results you want.

If not, you’ll have to do it manually by opening up Xcode, and go to the Mission Properties > Signing & Capabilities part.

The Signing & Capabilities part in Xcode is an assistive view, which implies that it analyses the undertaking information after which reveals the capabilities that are activated. In case you add a functionality with the +-Plus button, it creates and/or modifies the mandatory information within the undertaking.

In an automatic strategy, you’d wish to do these modifications from the command line. Unity’s PBXProject is a robust device to control Xcode tasks. Or there is a Python gem Xcodeproj. Typically, nonetheless, it doesn’t work dependable, because of conflicts between plugins. It is why I define right here shortly how you’d add them within the command line.

I submit this query with options right here, after I’ve not discovered any good rationalization or answer. I hope it saves the day for you on the market. I am utilizing Unity 2020, and Xcode 13.3, nevertheless it very doubtless works on older and newer variations, too.

Discover the file unity.entitlements (or every other .entitlements file which is already added to the undertaking). Then add the next content material to the file:

<key>aps-environment</key>
<string>growth</string>

For a take a look at deployment, the next is a attainable bash script code snippet:

echo "<?xml model="1.0" encoding="UTF-8"?>
<plist model="1.0">
<dict>
<key>aps-environment</key>
<string>growth</string>
</dict>
</plist>" > myProjectPath/Unity-iPhone/unity.entitlements

For a manufacturing deployment to the app retailer, the string worth must be manufacturing:

<key>aps-environment</key>
<string>manufacturing</string>

As lengthy, because the entitlement file is included within the undertaking, Xcode will work out that this app has/ought to now have the App Functionality “Push Notifications”

This app functionality is managed by an array worth within the undertaking’s plist, usually within the Data.plist file. The worth is as follows:

<key>UIBackgroundModes</key>
<array>
        <string>remote-notification</string>
</array>  

You may insert these traces simply with the mac program plistbuddy (a useful information right here):

set +e
/usr/libexec/PlistBuddy -c "Add :UIBackgroundModes array" ./projectPath/Data.plist || true
/usr/libexec/PlistBuddy -c "Add :UIBackgroundModes: string audio" ./projectPath/Data.plist || true
/usr/libexec/PlistBuddy -c "Add :UIBackgroundModes: string remote-notification" ./projectPath/Data.plist || true
set -e  

The above line provides the Background Mode functionality with “Audio” and “Distant Notification”. The opposite values as listed right here in Apple’s documentation. You may add extra modes to the BackgroundModes array by duplicating a line within the script above.

Hopefully, it was useful to you and allows you to create enjoyable video games. Get pleasure from!

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments