Skip to content
This repository has been archived by the owner on Oct 24, 2022. It is now read-only.

Missing swizzle for application:openURL:options in ios #750

Closed
guylando opened this issue Feb 21, 2019 · 19 comments · Fixed by #751
Closed

Missing swizzle for application:openURL:options in ios #750

guylando opened this issue Feb 21, 2019 · 19 comments · Fixed by #751

Comments

@guylando
Copy link

The swizzling is done to the deprecated openUrl version application:openURL:sourceApplication:annotation: and not the new one application:openURL:options and the new one is overridden without swizzling which causes bugs.
https://github.com/jeduan/cordova-plugin-facebook4/blob/master/src/ios/FacebookConnectPlugin.m#L789

What happens is that the new application:openURL:options is called and it calls the CDVAppDelegate implementation of the old application:openURL:sourceApplication:annotation: and doesnt let any other plugins the chance to get their application:openURL:options called.

Note also that cordova-ios 5 changed old openUrl with new one which probably will break this plugin, see: apache/cordova-ios#476 (comment)

So the solution is that there is no need to remove the current swizzling, just need to add a new swizzling for application:openURL:options like it is done here: https://github.com/nrikiji/twitter-connect-plugin/blob/master/src/ios/AppDelegate%2BTwitterConnect.m and stop overriding application:openURL:options without swizzling

Bugs caused by this:
#166
ionic-team/ionic-plugin-deeplinks#102

@peterpeterparker
Copy link
Collaborator

Feel free to provide a PR, I would be happy to merge it

guylando added a commit to guylando/cordova-plugin-facebook4 that referenced this issue Feb 21, 2019
@guylando
Copy link
Author

guylando commented Feb 21, 2019

@peterpeterparker Can you merge? #751
Important note: people using cordova-ios below 5 should copy the code in the following comment into their CordovaLib/Classes/Public/CDVAppDelegate.m file:
apache/cordova-ios#476 (comment)

I tested it and using this fix it finally called the openUrl of other plugins which wasn't working before.

@peterpeterparker
Copy link
Collaborator

@guylando I'm happy to merge it, but first could you describe what I should test precisely and/or provide a sample app to do so?

Also what do you mean with "people using cordova-ios below 5 should copy the code in the following comment into their CordovaLib/Classes/Public/CDVAppDelegate.m" ? couldn't we develop something which does "Cordova >= 5 do that else do that"?

@guylando
Copy link
Author

guylando commented Feb 21, 2019

Without this PR, other social login plugins openUrl was not called and in general deep linking got broken see: ionic-team/ionic-plugin-deeplinks#102
So you can add this plugin and another plugin which has some openUrl implementation and see that its not called without this PR.

People with cordova-ios below 5 dont have application:openURL:options in CDVAppDelegate.m

The CDVAppDelegate.m file is not part of this plugin, its part of cordova-ios template and the modification I described does not break anything and without it people will having missing logic anyway.

@guylando
Copy link
Author

Also this will solve #166

@peterpeterparker
Copy link
Collaborator

peterpeterparker commented Feb 21, 2019

Thx for the information. Have you got maybe one test app so I could give a try?

About Cordova-ios below 5, understood, if it doesn't break it's good. Should we add something in the README about that particularity? Could you extend the PR with it?

@guylando
Copy link
Author

guylando commented Feb 21, 2019

Unfortunately I don't have any test app other than my company full big app where I tested this (which is not open source).

Regarding cordova-ios (not cordova!) below 5 I think it depends on whether the app is run on a new ios which calls the new version of openUrl or old one. If its being run on older ios then old version is called and nothing changes. If its run on newer versions then as part of upgrading this plugin version the programmer should also do the change I described to insure that nothing breaks. However right now what happens on new ios is that instead of hooking openUrl, this plugin OVERRIDES openUrl. This means if some other plugin overrides openUrl as well then there is a raise condition and only one of them will work. That is what swizzling=hooking is supposed to solve, to seamlessly add logic without overriding anything. How do I modify a file in an existing PR?

@peterpeterparker
Copy link
Collaborator

Mmmh then I'll have to try out and build an test app, might take a bit then

Ok thx for the explanation. Just to be clear, the change (cf.: "If its run on newer versions then as part of upgrading this plugin version the programmer should also do the change") is only needed if we don't merge the PR right? as soon as we have merged the PR no one will have to do stuffs manually? correct?

If you can't modify the PR you could submit a new one, that would be ok and cool too?

P.S.: In any case, I'll not have time today to look deeper and stuffs. Will try in the next days, can't be sure but will try

@guylando
Copy link
Author

guylando commented Feb 21, 2019

After the PR: the plugin works with cordova-ios 5 without any modifications required and the plugin stops breaking other plugins but since that additional change is in cordova-ios template file which is not part of this plugin, it will be required to be modified manually (copy pasting the code from that link).

Before the PR: this plugin breaks other plugins and does not work with cordova-ios 5.

You still want me to add the required modification in the readme?

@peterpeterparker
Copy link
Collaborator

Well now I understand that the "manually modification" would be a must and therefore we should think about a better approach, we can't I think ask everyone to do manually change in cordova-ios

Any idea how we could improve that? Other way to solve the problem?

@peterpeterparker
Copy link
Collaborator

Like at least finding a hook and documenting it?

Also in the PR regarding Readme you write that the plugin doesn't work with Cordova-ios v5 which is wrong, I mean ok that particular deep linking case doesn't work but the other features are fine, plz improve the text, thx a lot

@guylando
Copy link
Author

I don't see anything written in the readme about the plugin not working with cordova-ios 5.
I don't have any more time to put into this. This requires first of all debugging and checking what happens right now without modifications and then maybe in runtime check and choose which method to call.
Using my fork my code works well right now.

@peterpeterparker
Copy link
Collaborator

You are right are read it to fast, my bad sorry

Ok then when you've got time or when someone as time, ping me

@peterpeterparker peterpeterparker changed the title URGENT: Missing swizzle for application:openURL:options in ios Missing swizzle for application:openURL:options in ios Feb 23, 2019
@t2wu
Copy link

t2wu commented May 22, 2019

I think the Swizzling in this plugin is failing. Cordova's own CDVAppDelegate's application:openURL:options: is not getting called.

Maybe avoid swizzling altogether. cordova-plugin-googleplus is using notification instead:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:) name:CDVPluginHandleOpenURLNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURLWithAppSourceAndAnnotation:) name:CDVPluginHandleOpenURLWithAppSourceAndAnnotationNotification object:nil];

@t2wu
Copy link

t2wu commented May 22, 2019

Or, just comment out the method under:

// This method is a duplicate of the other openURL method below, except using the newer iOS (9) API.

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options

I believe It's completely superfluous.

@guylando
Copy link
Author

@t2wu I think I described in the first message here in the paragraph starting with "So the solution.." the solution to "Cordova's own CDVAppDelegate's application:openURL:options: is not getting called"

@t2wu
Copy link

t2wu commented May 23, 2019

Thanks guylando I'll take a look at it if something goes wrong. Obviously this is open source, pure volunteering effort, so there is not anyone's responsibility. But this is so major, a pull request would be nice to be accepted.

@guylando
Copy link
Author

@t2wu old one not merged: #751

peterpeterparker pushed a commit that referenced this issue Jun 29, 2019
* Update FacebookConnectPlugin.m

Fix #750

* Update README.md

* Upgraded facebook sdk to 5.0.2

* Fix calls to deprecated facebook sdk functions on android which caused runtime crash when called.

* Removing Bolts framework ios dependency which is not used in ios sdk v5 facebook/facebook-ios-sdk@0bdd850

* Modernized FBSDKLoginKit usage according to
facebook/facebook-ios-sdk@6c4ac12
facebook/facebook-ios-sdk@5eae2d7:

1. Replaced FBSDKLoginManagerRequestTokenHandler by FBSDKLoginManagerLoginResultBlock
2. Replaced logInWithReadPermissions and logInWithPublishPermissions by logInWithPermissions

Modernized FBSDKShareKit usage according to facebook/facebook-ios-sdk@9b682bb:

1. Updated FBSDKShareOpenGraphAction init to actionWithType
2. Replaced FBSDKGraphRequestHandler by FBSDKGraphRequestBlock

* removed irrelevant files
@peterpeterparker
Copy link
Collaborator

The PR #751 has now been merged and I released a new version of the plugin v5.0.0

@guylando thx a lot and sorry for the delay. I'm not really using that much the plugin anymore that's why it's always difficult to find time.

Lindsay-Needs-Sleep pushed a commit to miloproductionsinc/cordova-plugin-facebook-connect that referenced this issue Mar 7, 2020
* Update FacebookConnectPlugin.m

Fix jeduan#750

* Update README.md

* Upgraded facebook sdk to 5.0.2

* Fix calls to deprecated facebook sdk functions on android which caused runtime crash when called.

* Removing Bolts framework ios dependency which is not used in ios sdk v5 facebook/facebook-ios-sdk@0bdd850

* Modernized FBSDKLoginKit usage according to
facebook/facebook-ios-sdk@6c4ac12
facebook/facebook-ios-sdk@5eae2d7:

1. Replaced FBSDKLoginManagerRequestTokenHandler by FBSDKLoginManagerLoginResultBlock
2. Replaced logInWithReadPermissions and logInWithPublishPermissions by logInWithPermissions

Modernized FBSDKShareKit usage according to facebook/facebook-ios-sdk@9b682bb:

1. Updated FBSDKShareOpenGraphAction init to actionWithType
2. Replaced FBSDKGraphRequestHandler by FBSDKGraphRequestBlock

* removed irrelevant files
Lindsay-Needs-Sleep pushed a commit to miloproductionsinc/cordova-plugin-facebook-connect that referenced this issue Mar 7, 2020
* Update FacebookConnectPlugin.m

Fix jeduan#750

* Update README.md

* Upgraded facebook sdk to 5.0.2

* Fix calls to deprecated facebook sdk functions on android which caused runtime crash when called.

* Removing Bolts framework ios dependency which is not used in ios sdk v5 facebook/facebook-ios-sdk@0bdd850

* Modernized FBSDKLoginKit usage according to
facebook/facebook-ios-sdk@6c4ac12
facebook/facebook-ios-sdk@5eae2d7:

1. Replaced FBSDKLoginManagerRequestTokenHandler by FBSDKLoginManagerLoginResultBlock
2. Replaced logInWithReadPermissions and logInWithPublishPermissions by logInWithPermissions

Modernized FBSDKShareKit usage according to facebook/facebook-ios-sdk@9b682bb:

1. Updated FBSDKShareOpenGraphAction init to actionWithType
2. Replaced FBSDKGraphRequestHandler by FBSDKGraphRequestBlock

* removed irrelevant files
Lindsay-Needs-Sleep pushed a commit to miloproductionsinc/cordova-plugin-facebook-connect that referenced this issue Mar 7, 2020
* Update FacebookConnectPlugin.m

Fix jeduan#750

* Update README.md

* Upgraded facebook sdk to 5.0.2

* Fix calls to deprecated facebook sdk functions on android which caused runtime crash when called.

* Removing Bolts framework ios dependency which is not used in ios sdk v5 facebook/facebook-ios-sdk@0bdd850

* Modernized FBSDKLoginKit usage according to
facebook/facebook-ios-sdk@6c4ac12
facebook/facebook-ios-sdk@5eae2d7:

1. Replaced FBSDKLoginManagerRequestTokenHandler by FBSDKLoginManagerLoginResultBlock
2. Replaced logInWithReadPermissions and logInWithPublishPermissions by logInWithPermissions

Modernized FBSDKShareKit usage according to facebook/facebook-ios-sdk@9b682bb:

1. Updated FBSDKShareOpenGraphAction init to actionWithType
2. Replaced FBSDKGraphRequestHandler by FBSDKGraphRequestBlock

* removed irrelevant files
Lindsay-Needs-Sleep pushed a commit to miloproductionsinc/cordova-plugin-facebook-connect that referenced this issue Mar 7, 2020
* Update FacebookConnectPlugin.m

Fix jeduan#750

* Update README.md

* Upgraded facebook sdk to 5.0.2

* Fix calls to deprecated facebook sdk functions on android which caused runtime crash when called.

* Removing Bolts framework ios dependency which is not used in ios sdk v5 facebook/facebook-ios-sdk@0bdd850

* Modernized FBSDKLoginKit usage according to
facebook/facebook-ios-sdk@6c4ac12
facebook/facebook-ios-sdk@5eae2d7:

1. Replaced FBSDKLoginManagerRequestTokenHandler by FBSDKLoginManagerLoginResultBlock
2. Replaced logInWithReadPermissions and logInWithPublishPermissions by logInWithPermissions

Modernized FBSDKShareKit usage according to facebook/facebook-ios-sdk@9b682bb:

1. Updated FBSDKShareOpenGraphAction init to actionWithType
2. Replaced FBSDKGraphRequestHandler by FBSDKGraphRequestBlock

* removed irrelevant files
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants