简体   繁体   中英

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. So, can I also use this Facebook URL scheme for launching my app? 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.

Any reason why I shouldn't just use the Facebook URL scheme in the meantime (like fb12345://test)?

Facebook's iOS SDK is open source, so you can actually step through the code and see what happens. 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.

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

  2. Pick a few scenarios, logged in to Facebook, not logged in to Facebook, logged in but with invalidated token.

  3. Step through those scenarios with the debugger and make sure you're not tripping any logic in the Facebook SDK.

  4. In the new version of your app, write a wrapper around the Facebook stuff:

     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. When it drops off to a point you're comfortable, start updating your URLs to point to the new scheme.

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. 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.

AFAIK the special url scheme that Facebook has you use contains your Facebook app 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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