Wizcorp / phonegap-facebook-plugin

The official plugin for Facebook in Apache Cordova/PhoneGap
Other
1.9k stars 2.01k forks source link

Apple's iOS 9 #1116

Open FristilWebDev opened 8 years ago

FristilWebDev commented 8 years ago

We got the following notification from Facebook. How will this afflict this plugin and apps built with it?

Apple's iOS 9 introduces many changes that will affect the Facebook integration of your app “appname”. You will need to make changes to preserve app functionality and ensure the best possible experience for people who use your iOS 9 app. Read this blog post for more information.

Action items you will need to take:

1: Download the new SDK for iOS 4.6 or v3.24. 2: The iOS 9 rollout introduces a new feature called App Transport Security which will require you to whitelist Facebook domains in your app's plist. 3: Update your app's plist to handle the changes to canOpenURL described here, so that your app can open dialogs in the Facebook app (for Login, share, invite friends, or native Likes). 4: Submit the new version of your app to Apple's app store. Please refer to this guide and changelog for more information.

FristilWebDev commented 8 years ago

Tested with the ios 9 GM and it dose not work if u have the Facebook application installed.

FristilWebDev commented 8 years ago

To clarify. Using phonegap build and it works in ios 8.4.1

sean-hill commented 8 years ago

:+1: Is the latest Facebook SDK going to be supported soon by this plugin? I'm looking to release for iOS 9 today, so my users don't have crashing applications on iOS 9 in a few days. I'm currently getting this error:

ld: 'Plugins/com.phonegap.plugins.facebookconnect/FacebookSDK.framework/FacebookSDK(FBLikeButtonBackgroundSelectedPNG.o)' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture arm64

clang: error: linker command failed with exit code 1 (use -v to see invocation)
scottweinert commented 8 years ago

:+1: Indeed...very time sensitive.

mikehayesuk commented 8 years ago

:+1: This is important. I wish I had a clue where to start with getting a PR together for this.

mablack commented 8 years ago

I made the following changes, and it seems to work - YMMV. Also, it seems to be authenticating through a popup browser window, not switching to the FB app as it does in 8.4.x - I'm not sure why yet.

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>facebook.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>                
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <key>fbcdn.net</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <key>akamaihd.net</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
    </dict>
</dict>

and

<key>LSApplicationQueriesSchemes</key>
<array>
    <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>
</array>
- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation
{
    if (!url) {
        return NO;
    }

    // iOS9 - https://github.com/ccsoft/cordova-facebook
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                 sourceApplication, @"sourceApplication", nil];
    [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url userInfo:dict]];

    return YES;
}
- (void)openURL:(NSNotification *)notification {
    // NSLog(@"handle url: %@", [notification object]);
    NSURL *url = [notification object];

    if (![url isKindOfClass:[NSURL class]]) {
        return;
    }

    // iOS 9 changes
    NSDictionary* params = notification.userInfo;
    if (params == nil) {
        return;
    }
    NSString *sourceApplication = [params objectForKey:@"sourceApplication"];
    [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
}

I'm definitely not an expert at this, so I can't guarantee that it won't break anything, but it seems to work with my limited testing.

JavierMartinz commented 8 years ago

I still getting @sean-hill's error

mablack commented 8 years ago

@JavierMartinz it sounds like it's still referencing the old version (3.21.1) of FacebookSDK.framework!

In your Xcode project, under "Frameworks", right-click on FacebookSDK.framework and choose "Show in Finder". Make sure you've updated this to version 3.24.0, and not the version that was bundled with phonegap-facebook-plugin.

If you installed the facebook-ios-sdk-3.24.0.pkg file I linked above, you should be able to find the updated FacebookSDK.framework in ~/Documents/FacebookSDK.

JavierMartinz commented 8 years ago

OK, I just checked the error again and this time is not caused by Facebook. It's caused by another plugin, Google Analytics, sorry. Thanks!!

mablack commented 8 years ago

@JavierMartinz hmm, strange!!

Did you replace the plugins/com.phonegap.plugins.facebookconnect/platforms/ios/FacebookSDK.framework copy as well? I replaced 2 copies of the framework.

Or maybe it's caching the old version in Xcode's "DerivedData" directory?

Mojo90 commented 8 years ago

@mablack thx! Does look good for me. Login does also happen in popup window but not sure if this is normal!? because I have a Share Action on Facebook and this is happening in Facebook-App...

mablack commented 8 years ago

@JavierMartinz great, I'm happy the issue is fixed!!

@Mojo90 I'm not sure if it's normal. The changelog for v3.24.0 has the following statement:

In addition, the SDK dialogs such as Login, Like, Share Dialogs automatically determine the best UI based on the device, including SFSafariViewController instead of Safari.

At a guess, maybe it determines that the Safari popup is the best UI for iOS 9...

There's some internal class methods in FBSession that set different "login behaviours", but you can't set them directly from the openActiveSessionWithReadPermissions methods.

Mojo90 commented 8 years ago

Yes that is what I mean with SFSafariViewController. Because if I open my share Dialog on iOS 9 it is doing it with FB-App and not with Pop-Up. Therefore this is maybe iOS 9-behavior. What is "a pity" with this solution is that if somebody is not logged in to FB via browser than you have to log in to it first. But if it is iOS 9-behavior (what I assume) we have to accept this...

Mojo90 commented 8 years ago

I discovered a "canOpenURL: failed for URL: "fbauth2://" - error: "(null)"" error. Thing it is caused by not updating to latest SDK regarding this thread: http://stackoverflow.com/questions/31991525/facebook-sdk-4-5-ios-9 maybe thus during login it is switching to popup Safari and not native app!?

mablack commented 8 years ago

@Mojo90 the Preparing for iOS 9 FAQ says that you can safely ignore that message, as long as you have the LSApplicationQueriesSchemes entry in your plist... I haven't seen that error in my testing yet, either!

Mojo90 commented 8 years ago

@mablack Yep I know I have this in my plist:

<key>LSApplicationQueriesSchemes</key>
    <array>
      <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>
    </array>
sean-hill commented 8 years ago

Is this plugin going to support Facebook's latest SDK version v4.6.0? It's pretty annoying that right now the user has to log into Facebook via Safari on iOS 9. Kinda defeats the purpose of this plugin.

Mojo90 commented 8 years ago

@sean-hill Do you surely know that best UI for Login is Facebook-App? Because as we already thought above it is maybe not as mentioned by @mablack

Mojo90 commented 8 years ago

btw I tested currently another App. For this App on iOS 9 you will be forwarded to Facebook-App but there is a pop up before which asks to open Facebook-App. Maybe if you do not force to use Facebook-App best UI for login would be SFSafariViewController

jawache commented 8 years ago

@sean-hill are you also seeing this?A Back to Safari thing on the top of the screen.

https://www.dropbox.com/s/43jbn6nda0kr681/Screenshot%202015-09-18%2014.18.46.png?dl=0

mlix11 commented 8 years ago

I also see the Back to Safari, it is clickable too...

jawache commented 8 years ago

It goes away if you background/foreground the app, i'm choosing to ignore it ;)

sean-hill commented 8 years ago

@Mojo90 I think it is. I originally used this plugin so my users never had to type in their username and password for Facebook, only tap that they except the permissions I was asking for. Now however, they have to type in their username and password for facebook, and also accept the permissions when it opens in SFSafariViewController. I wanted a 1 tap login process, to make my signup flow much more simple for my users, never having to open their keyboard.

@jawache yes I do see the Back to Safari.

mattchete commented 8 years ago

+1

olegdater commented 8 years ago

+1

jawache commented 8 years ago

FYI I fixed/worked-arround this by disabling bitcode, (xcode > build settings > bitcode).

From what I understand in XCode7 this is switched on by default and all it does is enable the end binary to be "patched" by apple w/out asking the app owners to rebuild and re-upload a new build.

So switching it off shouldn't have any impact to your app (i think). In any case switching it off fixed all the problems and the app is using the facebook app to sign-in.

Mojo90 commented 8 years ago

@jawache I did this because of Google Maps Plugin there you have to disable bitcode. But in my App the Safari-Window pops up for FB-Login

jawache commented 8 years ago

@Mojo90 for me works fine on my actual device for facebook login. (On emulator uses browser - don't have facebook installed on emulator)

infiniteloopltd commented 8 years ago

I found the following two additions to the info.plist helped Facebook authenticate in-app, rather than opening a browser;

<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict> <key>LSApplicationQueriesSchemes</key> <array> <string>fbauth</string> </array>

Obviously this is iOS9 only, and there may be a more secure way of doing it, but this works.

Mojo90 commented 8 years ago

@dananos I have this also in my Info.plist as you can see above and I also have bitcode disabled as mentioned by @jawache (btw: I tried it of course in my iphone 6+ with fb installed ;-) Any other hints how this could be solved or do I miss sth.?

rispig commented 8 years ago

@sean-hill @Mojo90 Ok, so I figured out how to prevent the safari popup and force the use of the native FB app. After doing all of @mablack steps, I noticed that when the app is opening the safari popup it also logs an error:

FBSDKLog: Cannot use the Facebook app or Safari to authorize, fbXXX is not registered as a URL Scheme

(XXX is my FB app id)

added it to the plist file and it works now

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fbXXX</string>
        </array>
    </dict>
</array>
Mojo90 commented 8 years ago

@rispig Thanks for your Info but unfortunately I already had this in my Info.plist :-(

rispig commented 8 years ago

@Mojo90 and you followed all the other steps? (upgrading FB SDK and adding the relevant keys to the plist file, and editing the .m file)

Mojo90 commented 8 years ago

@rispig yes I think otherwise FB-Plugin would not work under ios 9 at all ;-) I did what @mablack wrote. Bitcode is no, CFBundleURLTypes is set with my fb-app_id, LSApplicationQueriesSchemes is set, NSAllowsArbitraryLoads is allowed so not sure why it is still using safari pop up if all of you is reporting that it is using native app

Mojo90 commented 8 years ago

this is my relevant Plist:

    <key>CFBundleURLTypes</key>
    <array>
      <dict>
        <key>CFBundleURLSchemes</key>
        <array>
          <string>fb_APPID</string>
        </array>
      </dict>
      <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>com.develapp.meetfriends</string>
        <key>CFBundleURLSchemes</key>
        <array>
          <string>com.develapp.meetfriends</string>
        </array>
      </dict>
    </array>
    <key>CFBundleVersion</key>
    <string>1.0</string>
    <key>FacebookAppID</key>
    <string>appID</string>
    <key>FacebookDisplayName</key>
    <string>Meet Friends</string>
    <key>NSAppTransportSecurity</key>
    <dict>
      <key>NSAllowsArbitraryLoads</key>
      <true/>
      <key>NSExceptionDomains</key>
      <dict>
          <key>facebook.com</key>
          <dict>
              <key>NSIncludesSubdomains</key>
              <true/>
              <key>NSExceptionRequiresForwardSecrecy</key>
              <false/>
          </dict>
          <key>fbcdn.net</key>
          <dict>
              <key>NSIncludesSubdomains</key>
              <true/>
              <key>NSExceptionRequiresForwardSecrecy</key>
              <false/>
          </dict>
          <key>akamaihd.net</key>
          <dict>
              <key>NSIncludesSubdomains</key>
              <true/>
              <key>NSExceptionRequiresForwardSecrecy</key>
              <false/>
          </dict>
      </dict>
    </dict>
    <key>LSApplicationQueriesSchemes</key>
    <array>
      <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>whatsapp</string>
    </array>

and as I mentioned above SDK is updated and relevant code in App-Delegate and ConnectPlugin is adjusted

rispig commented 8 years ago

@Mojo90 just making sure - you don't really have the underscore after the "fb" prefix right? if you replaced both places the fb sdk is in and edited the .m file it should work

Did you try the "clean" command before building the app again?

Mojo90 commented 8 years ago

@rispig Yes "_APPID" is my real facebook app id also cleaned - Safaripopup is shown during FB-Login :-(

Edit: what did you mean by that "if you replaced both places the fb sdk"? Only updated the FacebookSDK in my Frameworks

rispig commented 8 years ago

@Mojo90 damn! what about the device logs? do you see any error before the popup is opened?

Mojo90 commented 8 years ago

@rispig Only the typical 2015-09-20 14:48:47.158 MeetFriends[2241:722402] THREAD WARNING: ['FacebookConnectPlugin'] took '108.867920' ms. Plugin should use a background thread. Nothing else for me at the moment...

My last edit: what did you mean by that "if you replaced both places the fb sdk"? Only updated the FacebookSDK in my Frameworks

rispig commented 8 years ago

@Mojo90 look at @mablack other comment - there are two places that the FBSDK file needs to be replaced

Mojo90 commented 8 years ago

yes replaced in Frameworks of XCode project and under facebookconnect plugins in plugins-folder. Nothing changed :-/

csheppard commented 8 years ago

Related: https://developers.facebook.com/bugs/786729821439894/ https://developers.facebook.com/bugs/1636969533209725/

Mojo90 commented 8 years ago

So as discussed there it is normal behavior with Safari Pop-Up right, @csheppard ? But I am wondering why other users here in this thread are saying it is working for them with native facebook app. and what is strange as mentioned above by me I have a share button and this share button does open the native app :-D !?

Edit: guys @rispig @jawache @dananos : are you really sure that you can use native app login on ios 9? because if you read the posts from @csheppard it seems really to be ios 9 design and no chance to open native app. but I tested the App "happn" and there I was asked to open Facebook-App on login and there it was a Native-Facebook-Login. But should not happen due to that posts

csheppard commented 8 years ago

I've downgraded the Facebook SDK back to version 20150810 and login appears to be working ok now via app switching. The only problem is "< Back to Facebook" remains in the top left of the screen.

uofmmike commented 8 years ago

@csheppard any chance you can give us the full rundown on what you have done? (.plist settings, sdk copy/paste/etc.) It seems you've wrestled this thing into shape

The "Back to facebook" I believe you are stuck with, one of the "design enhancements" of ios9.

csheppard commented 8 years ago

I'm actually using https://github.com/jeduan/cordova-plugin-facebook4 which includes the latest SDK but I just replaced the framework files with v4.5.0 (August 10th, 2015) downloaded from https://developers.facebook.com/docs/ios/downloads. I left Bolts at v1.2.2.

My .plist contains the recommended values:

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>fbapi</string>
  <string>fb-messenger-api</string>
  <string>fbauth2</string>
  <string>fbshareextension</string>
</array>

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>akamaihd.net</key>
    <dict>
      <key>NSExceptionRequiresForwardSecrecy</key>
      <false/>
      <key>NSIncludesSubdomains</key>
      <true/>
    </dict>
    <key>facebook.com</key>
    <dict>
      <key>NSExceptionRequiresForwardSecrecy</key>
      <false/>
      <key>NSIncludesSubdomains</key>
      <true/>
    </dict>
    <key>fbcdn.net</key>
    <dict>
      <key>NSExceptionRequiresForwardSecrecy</key>
      <false/>
      <key>NSIncludesSubdomains</key>
      <true/>
    </dict>
  </dict>
</dict>
csheppard commented 8 years ago

Although, FB docs say you should use the following for v4.5 or lower

<key>LSApplicationQueriesSchemes</key>
<array>
    <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>
</array>

But I haven't had any problems yet, I only use login and the graph api.

Mojo90 commented 8 years ago

mhh had bad experience with facebook4 (https://github.com/jeduan/cordova-plugin-facebook4/issues/40) maybe I'll try tomorrow on a clean project but don't want to add it to my current one because cost me 1 day+ to get back to wizcorp. But if you have solved it like this I'll have a look at it

rispig commented 8 years ago

@Mojo90 I'm sure I'm getting the native fb app login, I have no idea if the changes to the files are responsible for it or not since I'm really not an objective-c programmer :(

rispig commented 8 years ago

@Mojo90 omg, I just realized it was NOT the native fb app login, it was a full screen safari window that used the current FB cookie, so, I believe that we are in the same place