forked from Purus/launch_review
-
Notifications
You must be signed in to change notification settings - Fork 23
/
StoreRedirectPlugin.m
36 lines (31 loc) · 1.53 KB
/
StoreRedirectPlugin.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#import "StoreRedirectPlugin.h"
@implementation StoreRedirectPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"store_redirect"
binaryMessenger:[registrar messenger]];
StoreRedirectPlugin* instance = [[StoreRedirectPlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:channel];
}
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
if ([@"redirect" isEqualToString:call.method]) {
NSString *appId = call.arguments[@"ios_id"];
if (!appId.length) {
result([FlutterError errorWithCode:@"ERROR"
message:@"Invalid app id"
details:nil]);
} else {
NSString* iTunesLink;
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 11) {
iTunesLink = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/xy/app/foo/id%@", appId];
} else {
iTunesLink = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@", appId];
}
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
result(nil);
}
} else {
result(FlutterMethodNotImplemented);
}
}
@end