Skip to content

Commit

Permalink
adding nil check (flutter#1072)
Browse files Browse the repository at this point in the history
Adding nil checks in NSDictionary and default them to NSNull to prevent crashes.
  • Loading branch information
Chris Yang authored and andreidiaconu committed Feb 17, 2019
1 parent 8b14bc4 commit dece9a6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 4 additions & 0 deletions packages/package_info/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.2+1

* Fixed a crash on IOS when some of the package infos are not available.

## 0.3.2

* Updated Gradle tooling to match Android Studio 3.1.2.
Expand Down
15 changes: 6 additions & 9 deletions packages/package_info/ios/Classes/PackageInfoPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
if ([call.method isEqualToString:@"getAll"]) {
NSString* displayName =
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
// Cannot put nil into a map so return an empty string.
if (displayName == nil) {
displayName = @"";
}
result(@{
@"appName" : displayName,
@"packageName" : [[NSBundle mainBundle] bundleIdentifier],
@"version" : [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"],
@"appName" : [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]
?: [NSNull null],
@"packageName" : [[NSBundle mainBundle] bundleIdentifier] ?: [NSNull null],
@"version" : [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]
?: [NSNull null],
@"buildNumber" : [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]
?: [NSNull null],
});
} else {
result(FlutterMethodNotImplemented);
Expand Down
2 changes: 1 addition & 1 deletion packages/package_info/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for querying information about the application
package, such as CFBundleVersion on iOS or versionCode on Android.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/package_info
version: 0.3.2
version: 0.3.2+1

flutter:
plugin:
Expand Down

0 comments on commit dece9a6

Please sign in to comment.