gpt4 book ai didi

ios - 自定义 URL 方案错误 : This app is not allowed to query for scheme

转载 作者:行者123 更新时间:2023-11-28 05:36:27 24 4
gpt4 key购买 nike

我有 2 个应用程序,一个客户端和一个服务器。我正在尝试使用 URL 方案在 iOS 应用程序之间进行应用程序间通信

(我引用了这个 https://developer.apple.com/documentation/uikit/inter-process_communication/allowing_apps_and_websites_to_link_to_your_content/defining_a_custom_url_scheme_for_your_app 作为指南)

这是客户端的plist

<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string>com.test.serverendapp</string>
<key>CFBundleURLSchemes</key>
<array>
<string>serverendapp</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>com.test.serverendapp</string>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

iOS端代码

@IBAction func tapToClient(){
let urlsrting = "com.test.serverEndApp://requestInfo?userID='22'"
let url = URL(string: urlsrting)!
if UIApplication.shared.canOpenURL(url){

if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:]) { (success) in
print(" this is \(success)")
}

} else {
UIApplication.shared.openURL(url)
}
}else{

let alertController = UIAlertController(title: "Error", message:
"There is no such server app here", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: .default))

self.present(alertController, animated: true, completion: nil)

}
}

服务器端

列表

<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string>com.test.clientendapp</string>
<key>CFBundleURLSchemes</key>
<array>
<string>clientendapp</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>com.test.clientendapp</string>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

代码

 @IBAction func tapToServer(){
let urlsrting = "com.test.clientEndApp://provideInfo?username='Debanjan'"
let url = URL(string: urlsrting)!
if UIApplication.shared.canOpenURL(url){
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:]) { (success) in
print(" this is \(success)")
}

} else {
UIApplication.shared.openURL(url)
}
}else{
let alertController = UIAlertController(title: "Error", message:
"There is no such client app here", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: .default))

self.present(alertController, animated: true, completion: nil)

}
}
}

我从他们两个那里得到的只是

-canOpenURL: failed for URL: "com.test.clientEndApp://provideInfo?username='Debanjan'" - error: "This app is not allowed to query for scheme com.test.clientendapp"

-canOpenURL: failed for URL: "com.test.serverEndApp://requestInfo?userID='22'" - error: "This app is not allowed to query for scheme com.test.serverendapp"

我已经执行了所有步骤,但仍处于这种状态。帮助我意识到我做错了什么

我在 iPhone 8 iOS 12.2 模拟器上运行它,在 xcode 12.2 上

最佳答案

如果您注册,则以相反的方式进行:

<key>LSApplicationQueriesSchemes</key>
<array>
<string>com.test.clientEndApp</string>
</array>

你应该调用这个方案

let urlsrting = "com.test.clientEndApp://provideInfo?username='Debanjan'"

您的 LSApplicationQueriesSchemes 中缺少 com.test.

关于ios - 自定义 URL 方案错误 : This app is not allowed to query for scheme,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58502328/

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