pa2Codes
pa2Codes

Reputation: 63

Flutter/iOS: How can I use pubspec.yaml's App version in my NotificationServiceExtension Info.plist file?

The Flutter App version from pubspec.yaml can be used in the regular iOS Info.plist file by changing entries to

<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>

<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>

However I have created a Notification Service Extension to enable FCM Rich Text Push Notifications which is working fine. But when I change the Info.plist values of this extension to the same like above, the App fails with the following build error:

Unable to install /Users/pa/development/FlutterApps/myApp/build/ios/iphonesimulator/Runner.app on <ID>. This is sometimes caused by a malformed plist file:
ProcessException: Process exited abnormally:
An error was encountered processing the command (domain=IXErrorDomain, code=2):
Failed to create plugin placeholder for /Users/pa/development/FlutterApps/myApp/build/ios/iphonesimulator/Runner.app/PlugIns/NotificationService.appex
Failed to create promise.
Underlying error (domain=IXErrorDomain, code=2):
    Failed to set placeholder attributes com.mycompany.appid.NotificationService
    Failed to create promise.
  Command: xcrun simctl install <ID> /Users/pa/development/FlutterApps/myApp/build/ios/iphonesimulator/Runner.app
Error launching application on iPhone 11 Pro.

How can I use the same variables also in the Extensions Info.plist file? I think it's just some config but I can't figure it out.

Thanks!!

Upvotes: 3

Views: 2775

Answers (2)

Nani
Nani

Reputation: 11

Updated in Info.plist

<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>

Upvotes: 0

makstheimba
makstheimba

Reputation: 166

Flutter generates an xcconfig file with variables like FLUTTER_BUILD_NAME and FLUTTER_BUILD_NUMBER

To use these variables in an extension we need to do the following:

  1. Go to your extension Info.plist and add those variables. Like this

Bundle version string -- $(FLUTTER_BUILD_NAME)

Bundle version -- $(FLUTTER_BUILD_NUMBER)

  1. Go to your Project settings and select a Generated config file for your extension for each configuration. Like this

Upvotes: 4

Related Questions