简体   繁体   English

适用于Facebook的iOS URL方案

[英]iOS URL Scheme for Facebook

iOS Facebook required me to add a URL scheme so that users can login/sign up via Facebook in my app. iOS Facebook需要我添加URL方案,以便用户可以在我的应用程序中通过Facebook登录/注册。 So, can I also use this Facebook URL scheme for launching my app? 因此,我也可以使用此Facebook URL方案启动我的应用程序吗? I don't need to support deep linking--I'd just like to launch the app from a marketing email. 我不需要支持深层链接-我只想从市场营销电子邮件中启动该应用程序。 Clearly adding my own URL Scheme is preferred, but adding my own scheme will take a couple weeks before the app is in production. 显然,最好添加我自己的URL方案,但是添加我自己的方案将需要花费数周时间才能将应用程序投入生产。

Any reason why I shouldn't just use the Facebook URL scheme in the meantime (like fb12345://test)? 为什么我不应该同时使用Facebook URL方案(例如fb12345:// test)?

Facebook's iOS SDK is open source, so you can actually step through the code and see what happens. Facebook的iOS SDK是开源的,因此您实际上可以逐步查看代码,看看会发生什么。 I tried it on my app with a dummy URL fb12345://noop and found that A) there are a lot of tests being conducted and B) they all appear to fail with no side-effects. 我在我的应用程序上使用了虚拟URL fb12345://noop对其进行了尝试,发现A)正在进行大量测试,B)它们似乎都失败了,并且没有副作用。

Your milage may vary but my strategy would be: 您的里程可能会有所不同,但我的策略是:

  1. Use a URL that will remind you later what you were doing, eg fb12345://placeholder-until-Brett-does-something-better 使用一个可以在以后提醒您操作的URL,例如fb12345://placeholder-until-Brett-does-something-better

  2. Pick a few scenarios, logged in to Facebook, not logged in to Facebook, logged in but with invalidated token. 选择一些方案,登录Facebook,而不登录Facebook,但使用无效的令牌登录。

  3. Step through those scenarios with the debugger and make sure you're not tripping any logic in the Facebook SDK. 使用调试器逐步完成这些方案,并确保您没有在Facebook SDK中绊倒任何逻辑。

  4. In the new version of your app, write a wrapper around the Facebook stuff: 版本的应用中,为Facebook内容编写一个包装器:

     if ([url.scheme isEqualToString:facebookScheme] && ![url.host isEqualToString:@"placeholder-until-Brett-does-something-bette"]) { return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication]; } 
  5. Stop using this hack as soon as is reasonable. 在合理的情况下,请立即停止使用此黑客。 Track the number of users on the hacky version of your app. 在您的应用的hacky版本上跟踪用户数量。 When it drops off to a point you're comfortable, start updating your URLs to point to the new scheme. 当它下降到您感到舒适的程度时,就开始更新您的URL以指向新方案。

You're also going to have to accept the fact that things may happen where some third-party starts launching your app with that URL or you may have some active users who don't update the app to the non-hacky version. 您还必须接受这样的事实,即某些第三方可能会开始使用该URL启动您的应用程序,或者您可能有一些活跃用户未将应用程序更新为非hacky版本。 You may never have a good point to clean up your URL handler or point to anything other than that Facebook URL because the risks are too high. 清理URL处理程序或指向除Facebook URL之外的任何其他内容可能都不是一个好主意,因为风险太大。

AFAIK the special url scheme that Facebook has you use contains your Facebook app id. AFAIK,Facebook使用的特殊URL方案包含您的Facebook应用程序ID。 This is public information . 这是公共信息 So no harm done there. 因此,没有伤害。

As long the Facebook SDK won't misinterpret the data in the url you're opening the app with and would do something weird with it (for example crashing because of invalid parameters or whatever (unlikely but possible)) you should be good. 只要Facebook SDK不会误解您打开应用程序时使用的url中的数据,并且会对它做一些奇怪的事情(例如,由于无效参数或任何其他原因(不太可能,但可能)而崩溃),那么您应该很好。

That said, you'd need to post your 也就是说,您需要发布自己的

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation;

For me to be 100% nothing bad would happen. 对我而言,成为100%的人不会发生任何不好的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM