Flutter - Get app version in iOS using package_info - dart

I need to retrieve the app version from within Dart code in a Flutter project.
I am using package_info and in Android is working OK but in iOS the version property in PackageInfo is null.
My code:
Future<String> getVersion() async {
String base = getText(version);
PackageInfo packageInfo = await PackageInfo.fromPlatform();
return base.replaceAll("[name]", packageInfo.version);
}
Any help why is happening this or other way to retrieve the version?
In some places of internet it is said that the version must be retrieved from native config files but in my case those files contains a reference to the version defined in pubspec.yaml.
I am using Flutter version 1.0.0
Thanks.

This package_info on iOS requires the Xcode build folder to be rebuilt after changes to the version string in pubspec.yaml. Clean the Xcode build folder with: XCode Menu -> Product -> (Holding Option Key) Clean build folder.
see this

Add below two line in your plist file inside dict:
<key>CFBundleDisplayName</key>
<string>Package Info Example</string>

Related

Remove Last few charcters from a vriable in info.plist of xcode

I am using flutter to develop an ios and android app. and I use "$(FLUTTER_BUILD_NAME)$(FLUTTER_BUILD_NUMBER)"; to set the version name of the app.
As I use fastlane to automate the build version updates and want the version to show the build number.
Flutter requires version number to be of this format version: 3.2.0+6007 I have to use here the x.y.z+buildnumber. I want my app to have x.y.buildnumber as its version.
In android gradle I have achieved this as follows. I remove the last charcter of the version name and append version code
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
def flutterVersionName = localProperties.getProperty('flutter.versionName')
flutterVersionName=flutterVersionName.substring(0, flutterVersionName.length() - 1)+flutterVersionCode
In iOS I want to acheive the same. Currently I cab do it as this "$(FLUTTER_BUILD_NAME)$(FLUTTER_BUILD_NUMBER)"; which will make it x.y.z.buildnumber. How can i remove one last char from the $(FLUTTER_BUILD_NAME) in info.plist

How to get app's Build Number through Electron

I would like to get my MacOS app's build number at runtime, the same way I get the app version:
const { app } = require('electron');
console.log(app.getVersion()); // 1.0.0
The problem is that Electron doesn't seem to have any built-in method to retrieve the app's build number.
In a MacOS application, the build number is the one between parenthesis in the "About" panel. For example:
I'm packaging my Electron macOS app using forge.config.js, with the following config:
{
[...]
appVersion: '1.0.0',
buildVersion: '123456',
}
When I package my application for macOS, the About Panel shows the version correctly, displaying 1.0.0 (123456).
Is there a way to access the build number at runtime? Or, at least, injecting it into the packaged app so I can retrieve it somehow.
buildVersion ends up getting written to your Mac app bundle's your.app/Contents/Info.plist file under the CFBundleVersion field. So you'd have to read and parse the Info.plist xml file at runtime to get it, AFAIK there is no easier built in way. Not too hard to do, though it might just be easier for you to append this info to your appVersion like 1.0.0-123456 as that can be any string, there is no requirement that it be in semver or any particular format.

Is there a way to add Flutter to an extension Target on iOS xCode?

Assuming I have a basic flutter app and I add a target in xcode for the ios app. Would there be any way to link it to the main Flutter folder so I can do an "import Flutter" in the extension the same way it's done in the AppDelegate then start a FlutterEngine, MethodChannel etc locally in the extension ?
I partially succeded adding a module compiled as an "ios-framework" (otherwise with cocoapods there's a dependency conflict error) to the extension xcode target, yet this means including a redundant Flutter dependency and although it runs, I'm not sure at this point this is very stable... For this reason I'm wondering if there's a way to make an import of the main Flutter directly ?
Thanks

Xcode 13 - The project at '/Users/test.xcodeproj' cannot be opened because it is in a future Xcode project file format

When opening in Xcode 12.5 a project created with Xcode13, I get this error message:
"The project at '/Users/[...].xcodeproj' cannot be opened because it is in a future Xcode project file format. Adjust the project format using a compatible version of Xcode to allow it to be opened by this version of Xcode."
how am I supposed to adjust the project?
It is easy to change the project format in the Xcode file inspector:
But this is not the whole picture.
Another issue is the missing plist file in Xcode13 created projects.
To make the new project compatible in Xcode 12 you need to add a plist file. The best and quicker solution is to make a new project in Xcode 12 and copy and drop the plist file in the new Xcode13 project. Then make add the necessary changes for your project.
You will need to stop Xcode 13 to generate new plist files when you make changes. So return to the project in Xcode13 and set generate plist file to no under packaging in Build Settings:
I found very helpful information about this in a very good article on useyourloaf.com
I solved it selecting the target in the project settings, opening the identity and type window and changing to Xcode 12.0. Then open the project workspace again and done!
Check also the command line tools you are using in Xcode preferences --> locations

iOS or macOS project: duplicate interface definition for ViewController

I am trying to build a common Xcode project for macOS and iOS. My project directory structure is
MyApp
Common
AAPLAppDelegate.h
AAPLAppDelegate.mm
AAPLRenderer.h
AAPLRenderer.mm
MyApp_iOS
AAPLViewController.h
AAPLViewController.mm
main.m
MyApp_macOS
AAPLViewController.h
AAPLViewController.mm
main.m
build gives Duplicate interface definition for class 'AAPLViewController'.
I have added AAPLViewController.h in Build Phases -> Headers of corresponding macOS and iOS schemes.
I have also assigned corresponding macOS and iOS target membership to all files in MyApp_iOS and MyApp_macOS folders.
I tried comparing my project to an working macOS and iOS project but couldn't find a clue to avoid the error.
here is the git repo of it; macOS code isn't complete yet but iOS target should be built without above error.
You need to correctly setup your headers search paths. First, set ALWAYS_SEARCH_USER_PATHS to YES. If that will not work - add only needed headers to USER_HEADER_SEARCH_PATHS setting.

Resources