Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace deprecated openURL with open(_:options:) #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 40 additions & 30 deletions ios/Classes/LaunchexternalappPlugin.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "LaunchexternalappPlugin.h"

@implementation LaunchexternalappPlugin

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"launch_vpn"
Expand All @@ -9,45 +10,54 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
[registrar addMethodCallDelegate:instance channel:channel];
}


- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {

if ([@"getPlatformVersion" isEqualToString:call.method]) {
result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
} else
if ([@"isAppInstalled" isEqualToString:call.method]) {
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:call.arguments[@"package_name"]]]){
result(@(YES));
} else{
result(@(NO));}

} else if ([@"isAppInstalled" isEqualToString:call.method]) {
NSURL *appURL = [NSURL URLWithString:call.arguments[@"package_name"]];
if ([[UIApplication sharedApplication] canOpenURL:appURL]) {
result(@(YES));
} else {
result(@(NO));
}
} else if ([@"openApp" isEqualToString:call.method]) {
@try {
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:call.arguments[@"package_name"]]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:call.arguments[@"package_name"]]];
result(@("app_opened"));
} else
{
NSLog(@"Is reaching here1");
if(![@"false" isEqualToString: call.arguments[@"open_store"]]) {
NSLog(@"Is reaching here2 %@", call.arguments[@"app_store_link"]);

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:call.arguments[@"app_store_link"]]];
result(@("navigated_to_store"));
@try {
NSURL *appURL = [NSURL URLWithString:call.arguments[@"package_name"]];
if ([[UIApplication sharedApplication] canOpenURL:appURL]) {
[[UIApplication sharedApplication] openURL:appURL
options:@{}
completionHandler:^(BOOL success) {
if (success) {
result(@"app_opened");
} else {
result(@"failed_to_open_app");
}
}];
} else {
if (![call.arguments[@"open_store"] isEqualToString:@"false"]) {
NSURL *storeURL = [NSURL URLWithString:call.arguments[@"app_store_link"]];
[[UIApplication sharedApplication] openURL:storeURL
options:@{}
completionHandler:^(BOOL success) {
if (success) {
result(@"navigated_to_store");
} else {
result(@"failed_to_open_store");
}
result(@("App not found in the device"));
}];
} else {
result(@"App not found in the device");
}
}
@catch (NSException * e) {
NSLog(@"exception herre");
result(e);

}
} @catch (NSException *e) {
NSLog(@"Exception occurred: %@", e);
result([FlutterError errorWithCode:@"UNAVAILABLE"
message:@"Failed to open app"
details:e.reason]);
}
} else {
result(FlutterMethodNotImplemented);
}

}

@end

@end