通过 Bundle ID跳到第三方app

我原本以为这个是不太可能的,之前用的也都是通过 URL Schemes来跳转 ,人家的 Bundle ID也不会给你,可是最近有个项目就是这样的需求,找了很长时间,都是这三句话


    ClassLSApplicationWorkspace_class =objc_getClass("LSApplicationWorkspace");

    NSObject* workspace = [LSApplicationWorkspace_classperformSelector:@selector(defaultWorkspace)];

    BOOLisopen = [workspaceperformSelector:@selector(openApplicationWithBundleID:)withObject:@"第三方app的Bundle ID"];

后面没有了,琢磨了半天,将下面的代码补齐(我是将提示框封装了一下)


 if(isopen ==YES) {

        NSLog(@"打开了");

    }else{

        NSLog(@"没有app");

        [selfaddActionTotitle:@"提示"withMessage:@"您的手机上没有安装 x x x APP,是否前往下载?"withActionTitle:@"确定"withActionTitle2:@"取消"viewController:selfblock:^(BOOLisdelea) {

            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/us/app/id第三方APP的id?mt=8"]];

        }];

    }


#pragma mark 提示框

-(void)addActionTotitle:(NSString*)title withMessage:(NSString*)massage withActionTitle:(NSString*)actionTitle withActionTitle2:(NSString*)actionTitle2 viewController:(UIViewController*)vc block:(void(^)(BOOLisdelea))isok{


    UIAlertController *alertController=[UIAlertController alertControllerWithTitle:title message:massage        preferredStyle:( UIAlertControllerStyleAlert)];


    UIAlertAction *action=[UIAlertAction actionWithTitle:actionTitle style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {

        isok(YES);

    }];

    UIAlertAction *action2=[UIAlertAction actionWithTitle:actionTitle2 style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {

    }];

    [alertControlleraddAction:action];

    [alertControlleraddAction:action2];

    [vcpresentViewController:alertController animated:YES completion:nil];

}

你可能感兴趣的:(通过 Bundle ID跳到第三方app)