-(void)fpsPay2:(NSDictionary *)options callback:(UniModuleKeepAliveCallback)callback {
callback(@{@"code":@200,@"msg":@"start 2"},YES);
UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController;
UIViewController *currentShowingVC = [self findCurrentShowingViewControllerFrom:vc];
NSString *uti = [options objectForKey:@"uti"];
NSString *data = [options objectForKey:@"data"];
NSItemProvider *provider = [[NSItemProvider alloc]
initWithItem:data
typeIdentifier:uti];
NSExtensionItem *item = [[NSExtensionItem alloc] init];
item.accessibilityLabel = @"FPS";
item.attachments = @[ provider ];
UIActivityViewController *activityVC =
[[UIActivityViewController alloc] initWithActivityItems:@[ item ] applicationActivities:nil];
activityVC.popoverPresentationController.sourceView = currentShowingVC.view;
activityVC.completionHandler = ^(NSString *activityType, BOOL completed) {
if (completed) {
// 用户选择了某个活动完成分享
callback(@{@"code":@201,@"msg":@"分享"},YES);
} else {
// 用户取消了或者窗口关闭
callback(@{@"code":activityType,@"msg":@"取消"},YES);
}
};
[currentShowingVC presentViewController:activityVC animated:YES completion:NULL];
callback(@{@"code":@200,@"msg":@"end"},YES);
}
- (UIViewController *)findCurrentShowingViewControllerFrom:(UIViewController *)vc
{
// 递归方法 Recursive method
UIViewController *currentShowingVC;
if ([vc presentedViewController]) {
// 当前视图是被presented出来的
UIViewController *nextRootVC = [vc presentedViewController];
currentShowingVC = [self findCurrentShowingViewControllerFrom:nextRootVC];
} else if ([vc isKindOfClass:[UITabBarController class]]) {
// 根视图为UITabBarController
UIViewController *nextRootVC = [(UITabBarController *)vc selectedViewController];
currentShowingVC = [self findCurrentShowingViewControllerFrom:nextRootVC];
} else if ([vc isKindOfClass:[UINavigationController class]]){
// 根视图为UINavigationController
UIViewController *nextRootVC = [(UINavigationController *)vc visibleViewController];
currentShowingVC = [self findCurrentShowingViewControllerFrom:nextRootVC];
} else {
// 根视图为非导航类
currentShowingVC = vc;
}
return currentShowingVC;
}
IvanJiang123
- 发布:2023-11-01 18:00
- 更新:2023-11-01 18:00
- 阅读:178
0 个回复