{"id":286,"date":"2015-09-03T22:58:59","date_gmt":"2015-09-03T22:58:59","guid":{"rendered":"http:\/\/strawberrycode.com\/blog\/?p=286"},"modified":"2021-05-07T18:20:56","modified_gmt":"2021-05-07T16:20:56","slug":"get-your-facebook-login-ready-for-ios9-with-sfsafariviewcontroller","status":"publish","type":"post","link":"https:\/\/strawberrycode.com\/blog\/get-your-facebook-login-ready-for-ios9-with-sfsafariviewcontroller\/","title":{"rendered":"Get your Facebook login ready for iOS9 with SFSafariViewController"},"content":{"rendered":"\n<p>Here we are again, back on SFSafariViewController with the Facebook login integration this time! Facebook is getting ready for iOS 9 and got its SDK updated with very few changes on our side, yay! It is still in beta version as we speak but it&#8217;s working like a charm.<\/p>\n\n\n\n<p>Let&#8217;s see how to implement our Facebook login with SFSafariViewController in 3 easy steps.<\/p>\n\n\n\n<ol><li>First, make sure you use the right SDK (the beta one):<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"swift\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ In your Podfile \npod 'FBSDKCoreKit', :git => 'https:\/\/github.com\/facebook\/facebook-ios-sdk.git', :branch => 'release-4.6.0-beta1' \npod 'FBSDKLoginKit', :git => 'https:\/\/github.com\/facebook\/facebook-ios-sdk.git', :branch => 'release-4.6.0-beta1' \npod 'FBSDKShareKit', :git => 'https:\/\/github.com\/facebook\/facebook-ios-sdk.git', :branch => 'release-4.6.0-beta1'\n<\/pre>\n\n\n\n<ol start=\"2\"><li>Then, follow the Facebook instructions.<br>You probably have all that already set up minus the iOS 9 migration. It should be an easy step.<\/li><\/ol>\n\n\n\n<ul><li><a href=\"https:\/\/developers.facebook.com\/docs\/ios\/getting-started\" target=\"_blank\" rel=\"noreferrer noopener\">Getting started<\/a><\/li><li><a href=\"https:\/\/developers.facebook.com\/docs\/ios\/ios9\" target=\"_blank\" rel=\"noreferrer noopener\">Preparing Your Apps for iOS9<\/a><\/li><li><a href=\"https:\/\/developers.facebook.com\/docs\/facebook-login\/ios\/v2.4\" target=\"_blank\" rel=\"noreferrer noopener\">Facebook login<\/a> <br>At that point, you don&#8217;t even need step 3 if you followed Facebook&#8217;s instructions, especially step 6: &#8220;Connect Application Delegate&#8221;<\/li><\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"swift\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {\n  return [[FBSDKApplicationDelegate sharedInstance] application:application\n    openURL:url\n    sourceApplication:sourceApplication\n    annotation:annotation\n  ];\n}<\/pre>\n\n\n\n<p>But, if you want to keep it consistent with my <a href=\"http:\/\/strawberrycode.com\/blog\/sfsafariviewcontroller-and-oauth-the-instagram-example\/?utm_source=blog&amp;utm_medium=post&amp;utm_campaign=safarivc_oauth\" target=\"_blank\" rel=\"noreferrer noopener\">previous post<\/a>, follow the last step.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"swift\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ in your ApplicationDelegate\n\nfunc application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {\n\n\tif (sourceApplication == \"com.apple.SafariViewService\") {\n\t\tNSNotificationCenter.defaultCenter().postNotificationName(kSafariViewControllerCloseNotification, object: url)\n\n\t\t\/\/ test not mandatory, it's just to make the difference between potential returns\n\t\tif (url.absoluteString.containsString(\"fb\\(FACEBOOK_APP_ID):\/\/authorize\")) {\n\t\t\t\/\/ Facebook return is the key point here\n\t\t\treturn FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)\n\t\t}\n\t\treturn true\n\t}\n\treturn true\n}<\/pre>\n\n\n\n<ol start=\"3\"><li> Finally, make sure you use the Facebook return in the openURL function as follows: <\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"swift\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ in your ApplicationDelegate\n\nfunc application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {\n\n\tif (sourceApplication == \"com.apple.SafariViewService\") {\n\t\tNSNotificationCenter.defaultCenter().postNotificationName(kSafariViewControllerCloseNotification, object: url)\n\n\t\t\/\/ test not mandatory, it's just to make the difference between potential returns\n\t\tif (url.absoluteString.containsString(\"fb\\(FACEBOOK_APP_ID):\/\/authorize\")) {\n\t\t\t\/\/ Facebook return is the key point here\n\t\t\treturn FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)\n\t\t}\n\t\treturn true\n\t}\n\treturn true\n}<\/pre>\n\n\n\n<p>Build and run, et voil\u00e0, you can now login to your app with Facebook on the brand new SFSafariViewController.<br>No more app jumping and confusing configs, everything&nbsp;has been taken care of&nbsp;and it&#8217;s all Apple compliant. Sweet!<\/p>\n\n\n\n<p>Just one word about the other social network fellows:<\/p>\n\n\n\n<ul><li><strong>Twitter<\/strong>: <a href=\"https:\/\/get.fabric.io\/\" target=\"_blank\" rel=\"noopener\">Fabric<\/a> now handles everything (Login via Twitter, Crashlytics, MoPub, Digits). The integration in Xcode is as easy as their website is confusing. Don&#8217;t be surprised.<\/li><li><strong>Google<\/strong>: well, there is a <a href=\"https:\/\/developers.google.com\/identity\/sign-in\/ios\/start?ver=swift\" target=\"_blank\" rel=\"noopener\">new version of the SDK<\/a>. So exit the well-known <a href=\"http:\/\/stackoverflow.com\/questions\/15281386\/google-iphone-api-sign-in-and-share-without-leaving-app\/24577040#24577040\" target=\"_blank\" rel=\"noopener\">hack<\/a> a lot of us used. There is now a proper way to log in via Google on iOS. Let&#8217;s hope it will be approved by Apple as it doesn&#8217;t use the shiny SFSafariViewController (sob).<\/li><\/ul>\n\n\n\n<p>Quick reminder in case you missed it: Xcode 7 beta 6 is out since last week&nbsp;! It&#8217;s the last beta version before the official release on September 9. You can&nbsp;<a href=\"https:\/\/developer.apple.com\/xcode\/downloads\/\" target=\"_blank\" rel=\"noopener\">download<\/a>&nbsp;it here and have a look at the&nbsp;<a href=\"http:\/\/adcdownload.apple.com\/Developer_Tools\/Xcode_7_beta_6\/Xcode_7_beta_6_Release_Notes.pdf\" target=\"_blank\" rel=\"noopener\">release notes<\/a>&nbsp;too.<\/p>\n\n\n\n<p>Happy coding :)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here we are again, back on SFSafariViewController with the Facebook login integration this time! Facebook is getting ready for iOS 9 and got its SDK updated with very few changes on our side, yay! It is still in beta version as we speak but it&#8217;s working like a charm. Let&#8217;s see how to implement our Facebook login with SFSafariViewController in 3 easy steps. First, make sure you use the right SDK (the beta one): Then, follow the Facebook instructions.You probably have all that already set up minus the iOS 9 migration. It should be an easy step. Getting started Preparing &hellip; <a href=\"https:\/\/strawberrycode.com\/blog\/get-your-facebook-login-ready-for-ios9-with-sfsafariviewcontroller\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Get your Facebook login ready for iOS9 with SFSafariViewController<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":183,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[40],"tags":[42,57,17,55,58,51,50,41,54,56],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Facebook login on iOS9 with SafariViewController - StrawberryCode<\/title>\n<meta name=\"description\" content=\"Get your Facebook login ready for iOS9 with SFSafariViewController. And tips for Twitter and Google logins too ;)\" \/>\n<link rel=\"canonical\" href=\"https:\/\/strawberrycode.com\/blog\/get-your-facebook-login-ready-for-ios9-with-sfsafariviewcontroller\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Facebook login on iOS9 with SafariViewController - StrawberryCode\" \/>\n<meta property=\"og:description\" content=\"Get your Facebook login ready for iOS9 with SFSafariViewController. And tips for Twitter and Google logins too ;)\" \/>\n<meta property=\"og:url\" content=\"https:\/\/strawberrycode.com\/blog\/get-your-facebook-login-ready-for-ios9-with-sfsafariviewcontroller\/\" \/>\n<meta property=\"og:site_name\" content=\"StrawberryCode\" \/>\n<meta property=\"article:published_time\" content=\"2015-09-03T22:58:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-07T16:20:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/strawberrycode.com\/blog\/wp-content\/uploads\/2015\/04\/Apple_Swift_Logo-e1430073805246.png\" \/>\n\t<meta property=\"og:image:width\" content=\"200\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated reading time\">\n\t<meta name=\"twitter:data1\" content=\"3 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/strawberrycode.com\/blog\/#website\",\"url\":\"https:\/\/strawberrycode.com\/blog\/\",\"name\":\"StrawberryCode\",\"description\":\"Fruit for Thought\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/strawberrycode.com\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/strawberrycode.com\/blog\/get-your-facebook-login-ready-for-ios9-with-sfsafariviewcontroller\/#primaryimage\",\"inLanguage\":\"en-GB\",\"url\":\"https:\/\/strawberrycode.com\/blog\/wp-content\/uploads\/2015\/04\/Apple_Swift_Logo-e1430073805246.png\",\"contentUrl\":\"https:\/\/strawberrycode.com\/blog\/wp-content\/uploads\/2015\/04\/Apple_Swift_Logo-e1430073805246.png\",\"width\":200,\"height\":200,\"caption\":\"Apple Swift Logo\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/strawberrycode.com\/blog\/get-your-facebook-login-ready-for-ios9-with-sfsafariviewcontroller\/#webpage\",\"url\":\"https:\/\/strawberrycode.com\/blog\/get-your-facebook-login-ready-for-ios9-with-sfsafariviewcontroller\/\",\"name\":\"Facebook login on iOS9 with SafariViewController - StrawberryCode\",\"isPartOf\":{\"@id\":\"https:\/\/strawberrycode.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/strawberrycode.com\/blog\/get-your-facebook-login-ready-for-ios9-with-sfsafariviewcontroller\/#primaryimage\"},\"datePublished\":\"2015-09-03T22:58:59+00:00\",\"dateModified\":\"2021-05-07T16:20:56+00:00\",\"author\":{\"@id\":\"https:\/\/strawberrycode.com\/blog\/#\/schema\/person\/c328d959959928f47281d7a0ec779e2a\"},\"description\":\"Get your Facebook login ready for iOS9 with SFSafariViewController. And tips for Twitter and Google logins too ;)\",\"breadcrumb\":{\"@id\":\"https:\/\/strawberrycode.com\/blog\/get-your-facebook-login-ready-for-ios9-with-sfsafariviewcontroller\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/strawberrycode.com\/blog\/get-your-facebook-login-ready-for-ios9-with-sfsafariviewcontroller\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/strawberrycode.com\/blog\/get-your-facebook-login-ready-for-ios9-with-sfsafariviewcontroller\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/strawberrycode.com\/blog\/\",\"url\":\"https:\/\/strawberrycode.com\/blog\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/strawberrycode.com\/blog\/get-your-facebook-login-ready-for-ios9-with-sfsafariviewcontroller\/\",\"url\":\"https:\/\/strawberrycode.com\/blog\/get-your-facebook-login-ready-for-ios9-with-sfsafariviewcontroller\/\",\"name\":\"Get your Facebook login ready for iOS9 with SFSafariViewController\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/strawberrycode.com\/blog\/#\/schema\/person\/c328d959959928f47281d7a0ec779e2a\",\"name\":\"StrawberryCode\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/strawberrycode.com\/blog\/wp-json\/wp\/v2\/posts\/286"}],"collection":[{"href":"https:\/\/strawberrycode.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/strawberrycode.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/strawberrycode.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/strawberrycode.com\/blog\/wp-json\/wp\/v2\/comments?post=286"}],"version-history":[{"count":14,"href":"https:\/\/strawberrycode.com\/blog\/wp-json\/wp\/v2\/posts\/286\/revisions"}],"predecessor-version":[{"id":594,"href":"https:\/\/strawberrycode.com\/blog\/wp-json\/wp\/v2\/posts\/286\/revisions\/594"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/strawberrycode.com\/blog\/wp-json\/wp\/v2\/media\/183"}],"wp:attachment":[{"href":"https:\/\/strawberrycode.com\/blog\/wp-json\/wp\/v2\/media?parent=286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/strawberrycode.com\/blog\/wp-json\/wp\/v2\/categories?post=286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/strawberrycode.com\/blog\/wp-json\/wp\/v2\/tags?post=286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}