#import "urlLauncherPlugin.h"

@implementation UrlLauncherPlugin

// 实现插件的启动方法
- (void)launch:(NSDictionary*)arguments callback:(UniReturnValueCallback)callback {
    NSString *urlString = arguments[@"url"];
    if (!urlString) {
        callback(@{@"success": @(NO), @"message": @"URL is missing"});
        return;
    }

    NSURL *url = [NSURL URLWithString:urlString];
    if (!url) {
        callback(@{@"success": @(NO), @"message": @"Invalid URL"});
        return;
    }

    dispatch_async(dispatch_get_main_queue(), ^{
        UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
        SFSafariViewController *safariVC = [[SFSafariViewController alloc] initWithURL:url];
        [rootVC presentViewController:safariVC animated:YES completion:^{
            callback(@{@"success": @(YES)});
        }];
    });
}

@end
