I am implementing universal deep linking in my app. When I registered my different domains, it creates an AppName.entitlements file
I would like to read the values of this file like a plist.
I tried
if let path = NSBundle.mainBundle().pathForResource("AppName", ofType:
"entitlements") { }
but it returns nil
Is it possible to read such files?
Check the Entitlements In Your Build Log and App You'll find the name of the provisioning profile Xcode used to sign your app in the invocation of the codesign tool's command-line parameters. This command prints a plist that contains all of the entitlements built into the app.
Entitlements are special app capabilities and security permissions granted to applications that are correctly configured to use them. In iOS, apps run in a sandbox, which provides a set of rules that limit access between the application and certain system resources or user data.
The solution I found:
add the appGroup
into Info.Plist
file
<key>appGroup</key>
<string>group.com.acronis.mobile.ios.development</string>
To read the string use the code below:
extension String {
// MARK: - Static
static var appGroup: String = {
guard let bundleAppGroup = Bundle.main.infoDictionary?["appGroup"] as? String else {
fatalError("The application must contain appGroup in Info.plist file")
}
return bundleAppGroup
}()
}
Change the entitlements
and Info.plist
at before build time using your custom script if needed.
That file isn't copied in to your app (see Xcode's target checkbox). It is only used for building
the entitlements are a config file for Xcode
so: no
I dove into this subject a bit and it is actually quite simple.
You use a run script to grab the entitlements and merge it into Info.plist:
ENTITLEMENTS= # Path to Project.entitlements #
INFOPLIST= # Path to Info.plist #
echo "Writing entitlements to Info.plist";
KEY="entitlements-from-script";
/usr/libexec/PlistBuddy -c "delete $KEY" "$INFOPLIST";
/usr/libexec/PlistBuddy -c "add $KEY dict" "$INFOPLIST";
/usr/libexec/PlistBuddy -c "merge $ENTITLEMENTS $KEY" "$INFOPLIST";
Now you can use it in code:
let entitlements = Bundle.main.infoDictionary?["entitlements-from-script"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With