j0j00 / flutter_user_agent

Retrieve Android/iOS device user agents in Flutter.
https://pub.dev/packages/flutter_user_agent
BSD 2-Clause "Simplified" License
25 stars 55 forks source link

unknown right parentheses in iOS #16

Open ogata-k opened 3 years ago

ogata-k commented 3 years ago

in iOS, use this function.

FlutterUserAgent.getPropertyAsync('packageUserAgent');

get followed value

<app_name>/1.1.0.59 CFNetwork/1125.2 Darwin/20.2.0 (iPhone/11 iOS/13.4))

What is last right parentheses?

I think the illegal right parentheses is occurred, because 'packageUserAgent' key's value has an illegal right parentheses in this function in the file ios/Classes/FlutterUserAgentPlugin.m.

- (void)constantsToExport:(void  (^ _Nullable)(NSDictionary * _Nonnull constants))completionHandler
{
    UIDevice *currentDevice = [UIDevice currentDevice];

    NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"] ?: [NSNull null];
    NSString *appVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] ?: [NSNull null];
    NSString *buildNumber = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"] ?: [NSNull null];
    NSString *darwinVersion = [self darwinVersion];
    NSString *cfnVersion = [NSBundle bundleWithIdentifier:@"com.apple.CFNetwork"].infoDictionary[@"CFBundleShortVersionString"];
    NSString *deviceName = [self deviceName];

    NSString *userAgent = [NSString stringWithFormat:@"CFNetwork/%@ Darwin/%@ (%@ %@/%@)", cfnVersion, darwinVersion, deviceName, currentDevice.systemName, currentDevice.systemVersion];

    [self getWebViewUserAgent:^(NSString * _Nullable webViewUserAgent, NSError * _Nullable error) {
        completionHandler(@{
          @"isEmulator": @(self.isEmulator),
          @"systemName": currentDevice.systemName,
          @"systemVersion": currentDevice.systemVersion,
          @"applicationName": appName,
          @"applicationVersion": appVersion,
          @"buildNumber": buildNumber,
          @"darwinVersion": darwinVersion,
          @"cfnetworkVersion": cfnVersion,
          @"deviceName": deviceName,
          @"packageUserAgent": [NSString stringWithFormat:@"%@/%@.%@ %@)", appName, appVersion, buildNumber, userAgent],
          @"userAgent": userAgent,
          @"webViewUserAgent": webViewUserAgent ?: [NSNull null]
        });
    }];
}
j0j00 commented 3 years ago

That's a nice spot, I'm happy to take a PR addressing it if you've tested the change and are happy to.

I don't do much flutter dev currently so it's hard to find the motivation to work on it