Answers:
在为iOS 9构建应用程序时,您可以继续使用URL方案,并且要调用URL方案,现在需要在应用程序Info.plist中声明它们。有一个新的密钥LSApplicationQueriesSchemes,在这里您将需要添加canOpenURL所在的方案列表。
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbauth2</string>
</array>
如果您使用的是iOS9,那么这对于更新info.plist文件很重要。您只需要执行3个步骤1.转到info.plist。2.添加一个字段,即LSApplicationQueriesSchemes NSArray数据类型。3.添加一个NSString数据类型,名称为fbauth2。
对于FaceBook SDK v4.6.0,将以下密钥添加到您的plist文件中:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
not
告诉您要执行此操作,好指出了!
只需按照Facebook的说明进行操作:为iOS9准备您的应用程序
苹果在他们的文章中提到:隐私和您的应用程序主题演讲2015
请只是不要将其添加到您的CFBundleURLSchemes ...中,这实际上会阻止任何应用在Facebook auth上的尝试,从而导致弹出窗口显示“ X应用要打开”对话框...
您不想这样做。
cf:
https://developers.facebook.com/docs/applinks/ios
https://www.fireeye.com/blog/threat-research/2015/04/url_masques_on_apps.html
https://www.reddit.com/r/workflow/comments/2tlx29/get_url_scheme_of_any_app
由于我的测试目标无法访问主捆绑包,因此在运行Kiwi测试时得到了此信息。所以我不得不一个条件添加到isRegisteredCanOpenURLScheme
在FBSDKInternalUtility.m
+ (BOOL)isRegisteredCanOpenURLScheme:(NSString *)urlScheme
{
static dispatch_once_t fetchBundleOnce;
static NSArray *schemes = nil;
dispatch_once(&fetchBundleOnce, ^{
schemes = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"LSApplicationQueriesSchemes"];
if (!schemes) { // This is a work around for our Kiwi tests as the Specs target doesn't have access to main bundle
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSString *path = [bundle pathForResource:@"Info" ofType:@"plist"];
NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:path];
schemes = [dictionary valueForKey:@"LSApplicationQueriesSchemes"];
}
});
return [schemes containsObject:urlScheme];
}
Write the below code in your info.plist under the **LSApplicationQueriesScheme**
<string>fbapi</string>
<string>fbapi20130214</string>
<string>fbapi20130410</string>
<string>fbapi20130702</string>
<string>fbapi20131010</string>
<string>fbapi20131219</string>
<string>fbapi20140410</string>
<string>fbapi20140116</string>
<string>fbapi20150313</string>
<string>fbapi20150629</string>
<string>fbauth</string>
<string>fbauth2</string>
<string>fb-messenger-api20140430</string>
<string>fb-messenger-platform-20150128</string>
<string>fb-messenger-platform-20150218</string>
<string>fb-messenger-platform-20150305</string>
您可以尝试以下代码 swift 5.0
extension Bundle {
static let externalURLSchemes: [String] = {
guard let urlTypes = main.infoDictionary?["LSApplicationQueriesSchemes"]
as? [String] else {
return []
}
return urlTypes
}()
}
您可以使用 Bundle
guard Bundle.externalURLSchemes.contains(URLScheme) else {
return
}