Custom URL Scheme Error : This app is not allowed to query for scheme
Custom URL Scheme Error : This app is not allowed to query for scheme
我有 2 个应用程序,一个客户端和一个服务器。我正在尝试使用 URL 方案
在 ios 应用程序之间进行应用程序间通信
这是客户端的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)
}
}
服务器端
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.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"
我已经执行了所有步骤,但仍处于这种状态。帮助我意识到我做错了什么
我是运行它在iPhone8iOS12.2模拟器上,在xcode12.2
上
如果你注册了,你就是在做相反的事情:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>com.test.clientEndApp</string>
</array>
你应该调用这个方案
let urlsrting = "com.test.clientEndApp://provideInfo?username='Debanjan'"
您 LSApplicationQueriesSchemes
中缺少 com.test.
所以感谢@Lu_指出我的错误
积分:
1.客户端应用程序将具有服务器应用程序的方案,反之亦然
2. LS应该有一个完整的名字,没有这样的com.test或者什么不是
我有 2 个应用程序,一个客户端和一个服务器。我正在尝试使用 URL 方案
在 ios 应用程序之间进行应用程序间通信这是客户端的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)
}
}
服务器端
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.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"
我已经执行了所有步骤,但仍处于这种状态。帮助我意识到我做错了什么
我是运行它在iPhone8iOS12.2模拟器上,在xcode12.2
上如果你注册了,你就是在做相反的事情:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>com.test.clientEndApp</string>
</array>
你应该调用这个方案
let urlsrting = "com.test.clientEndApp://provideInfo?username='Debanjan'"
您 LSApplicationQueriesSchemes
com.test.
所以感谢@Lu_指出我的错误
积分: 1.客户端应用程序将具有服务器应用程序的方案,反之亦然 2. LS应该有一个完整的名字,没有这样的com.test或者什么不是