gpt4 book ai didi

ios - 在 IOS 中打开 URL 方案

转载 作者:可可西里 更新时间:2023-11-01 06:21:25 26 4
gpt4 key购买 nike

我有 2 个应用程序,它们用于不同的目的,我不应该允许用户在同一设备上使用这两个应用程序。如何检查是否安装了其他应用程序?我想我可以使用 Open URL 来做到这一点,方法是放置不起作用的应用程序包 id,我无法获取我的应用程序的 url例如:“fb://”

       if ([[UIApplication sharedApplication] canOpenURL:@"My App URL"]) {
//App installed
}
else{
//App Not installed
}

最佳答案

你有 2 个应用程序。现在你想从第二个应用程序打开第一个应用程序。我会给你逐步说明,请按照此操作。

我的第一个应用程序名称是 LinkAppSample,第二个应用程序名称是 LinkSecondApp

STEP 1: Add the below things in first app LinkAppSample

<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.example.com</string>
<key>CFBundleURLSchemes</key>
<array>
<string>chatapp</string>
</array>
</dict>
</array>

然后你需要添加

<key>LSApplicationQueriesSchemes</key>
<array>
<string>chatapp</string>
</array>

请看下面的截图

enter image description here

STEP 2: Go to Second App.My Second App Name is LinkSecondApp.Now click LinkSecondApp project.Click TARGETS and click info.Then Click URL Type and add or write or set name in URL Schemes Target->Info->URL types->Add url types

目标的首次点击信息

enter image description here

然后单击 URL Tpes。单击后会显示 + 符号。

enter image description here

现在单击 + 符号并在 URL Schemes 中提供应用程序的名称。您必须将 Rote 设置为 Viewer

enter image description here

注意:您的 URL Schemes 名称必须相同(第一个 App Plist 名称和第二个 App URL Schemes 名称在这里是 chatapp)。

STEP 3: Now you must add code in Second application LinkSecondApp for opening the First app.

LinkSecondApp.m

-(IBAction)actionOpenFirstApp:(id)sender
{
NSString *customURL = @"chatapp://";
UIApplication *application = [UIApplication sharedApplication];
NSURL *URL = [NSURL URLWithString:@"chatapp://"];
if ([application respondsToSelector:@selector(openURL:options:completionHandler:)])
{
[application openURL:URL options:@{}
completionHandler:^(BOOL success) {
NSLog(@"Open %@: %d",customURL,success);
}];
}
else {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Error!" message:@"No Custom URL is defined" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:ok];
[self presentViewController:alertController animated:YES completion:nil];
}
}

关于ios - 在 IOS 中打开 URL 方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41935987/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com