Facebook logout programmatically in Xamarin ios in Visual Studio - ios

I have an application in IOS in which there is a Facebook Login Button.
when ever user clicks this Facebook login button My app redirects the user to the Facebook App installed in my device. So I want to logout the user from the application as soon as he leaves the facebook app and comes to my app.
i redirect the user to the facebook app using
NSUrl url = NSUrl.FromString("fb://profile/<id>");
UIApplication.SharedApplication.OpenUrl(url);

I found the Facebook login documentation. As the documentation described, I think you have added the CFBundleURLTypes, like this:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb[APP_ID]</string>
</array>
</dict>
</array>
It means that Facebook will trigger the openURL to return back to your app via the URLScheme you have set here.
So, you can override OpenUrl(UIApplication app, NSUrl url, NSDictionary options) in AppDelegate.cs, and the parameters url or options contain the information related to Facebook. So, you can identify the resource.
public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
{
Console.WriteLine(url);
Console.WriteLine(options);
return true;
}
According to this, you can do the action you want when return back from Facebook.

Are you using the Xamarin Facebook SDK? If yes you can do this to log out:
new LoginManager().LogOut();

Related

iOS Swift LinkedIn App URL Scheme is not working

I want to open user linedIn profile(in linkedIn Native App) from my App.
I tried this but its just opening linekdin App but not profile page: URL Scheme for Linkedin
I have added URLSchemes as well
<key>LSApplicationQueriesSchemes</key>
<array>
<string>linkedin</string>
</array>
This is my code
if let linkedinUrl = URL(string: "linkedin://profile?id=parmarvhv"),
UIApplication.shared.canOpenURL(linkedinUrl) {
UIApplication.shared.open(linkedinUrl, options: [:], completionHandler: nil)
}
LinkedIn Web Url is this: https://www.linkedin.com/in/parmarvhv/
What is the correct way to open user profile?
This code works for swift 5:
Opening a LinkedIn page:
linkedin://company/binance
Opening a LinkedIn profile:
linkedin://profile/binance
Well, it's not documented. so you can't rely on it.
But, using linkedin://in/{username} works for me.

No reaction to Deep-link defined in info.plist

i defined a deep-link in info.plist like this :
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.myapp.customer</string>
<key>CFBundleURLSchemes</key>
<array>
<string>myapp.com</string>
</array>
</dict>
</array>
but in Safari there's no reaction to this link and this message shows up :
Safari cannot open the page because the server can not be found
Everything is checked and i did as tutorials and still nothing happens!
The CFBundleURLSchemes field should be filled with a scheme, not a url. Schemes come before the url to tell the browser what action to take. For example, https:// is a scheme that tells the browser to establish a secure connection. An Apple URI scheme is simply you telling the browser that you want URLs with your custom scheme (i.e. customScheme://) to be handled by your app. HTTP and HTTPS are reserved for Safari on iOS. To allow customScheme://example/path to open your app. Just change that field to customScheme.
If you would like to register normal web URLs to handle your links you will have to integrate Universal Links. These can be a pain to set up so I recommend using the Branch iOS SDK. Their deep linking is free and provides more features on top of Universal Links.
Make sure you have this method in AppDelegate.Swift
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
if url.scheme != nil && url.scheme!.hasPrefix(""){
//Deep linking link should be like this : 'yourAppScheme'
if(url.host?.contains("page"))!{
if(url.path.contains("/yourhoststring")){
// do some work
}
}
}
//default
return false
}
Your Url scheme should be like this : [scheme]://[host]/[path]
Here is the link for detailed tutorial:
http://blog.originate.com/blog/2014/04/22/deeplinking-in-ios/

How to get response after integrating UPI using hyperlink

In my iOS application, I need to accept payments from the user. I am using UPI for the same. I have followed the following document provided by UPI
http://www.npci.org.in/documents/UPI-Linking-Specs-ver-1.1_draft.pdf
I have created a deeplink as stated in the document. UIApplication.shared.open is used to open the deeplink url so that it opens any installed PSP(Payment Service Provider) application in my phone(like PhonePe, BHIM etc)
func payButtonClicked() {
guard let urlString = "upi://pay?pa=samplevpa#ybl&pn=Sample Name&am=1&cu=INR".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
else {
return
}
guard let url = URL(string: urlString) else {
return
}
if !UIApplication.shared.canOpenURL(url) {
print("url cannot be opened")
return
}
UIApplication.shared.open(url, options: [:], completionHandler: { (success) in
print(success)
})
}
I have registered my application with custom URL schemes and have added the scheme upi for ApplicationQueriesScheme in plist file
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>SampleApp</string>
</array>
<key>CFBundleURLName</key>
<string>com.company.SampleApp</string>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>upi</string>
</array>
It is opening the PSP application and I'm able to make the transaction. The problem is I'm not able to get the response back from the PSP application. There is no callback method to UIApplication.shared.open method. I need to get the status of the transaction back from the PSP application and show the status to the user. Any help appreciated
the NPCI UPI Linking Specification states that the URL parameter used in the payment link is for information purpose which the payment apps may use to provide additional information to the payer upon clicking the link.
The link is only expected to show transaction details by the merchant or party that invoked the transaction.
It is not meant as a callback URL or a web hook for completion of transaction.
Based on the below workflow, you need to have a tie up with Payer/Payee PSP to get notified for your payments. In your scenario, you are required to check with your bank PSP for getting notified on the payment receipt to your accoutns.
I could not see a way for individual Initiator to get notified.
Feel free to correct me.
Have not tried it but it was mentioned in the document about a url parameter on clicking of which we should show the transaction details to the user.
This should be a URL when clicked provides customer with further
transaction details like complete bill details, bill copy, order
copy, ticket details, etc. This can also be used to deliver digital
goods such as mp3 files etc. after payment.
We could send a url with a url scheme that redirects to the app or an universal link that our app can handle.
Again I have not tried this so I do not know if this works as I think it should or whether it would exactly solve your issue.
https://www.npci.org.in/sites/all/themes/npcl/images/PDF/UPI_Linking_Specs_ver_1.5.1.pdf
You can use the url parameter to pass your website url with the get method with order id or payment id as parameter. Once the payment is successful, it is mandate the UPI provider to hit the URL.
The purpose of the URL should be keep updating the transaction status and trigger then end user an email or SMS with the transaction status.

Google Sign-In is not returning to my app

I have a problem with Google Sign-in not redirecting back to my app.
I have followed the steps (https://developers.google.com/identity/sign-in/ios/start-integrating), installed cocoapods, downloaded the GoogleService-Info.plist (added it to all of my targets), added the URL Types (my bundle identifier and then my reverse client ID to my target and followed the steps line by line.
Here is the source code of the plist CFBundleURLTypes:
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>MY_REVERSE_CLIENT_ID</string>
</array>
<key>CFBundleURLName</key>
<string>MY_BUNDLE_ID</string>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>MY_BUNDLE_ID</string>
</array>
<key>CFBundleURLName</key>
<string>MY_BUNDLE_ID</string>
</dict>
In the App Delegate, I configured the [GGLContext sharedInstance] and in application openURL method I added-
return [[GIDSignIn sharedInstance] handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
If the Google Plus app is not installed, then safari opens in app just fine and once signed in, the delegate callback methods work just as expected.
I believe this is an issue with iOS9. This worked before on iOS8.
I have also added com-google-gidconsent and com-google-gidconsent-google to LSApplicationQueriesSchemes in my plist, as I saw another post that said that could be the issue.
I have checked that in the google developer portal my bundle ID matches my project's bundle id as well as the client id and reverse client id are correct.
I have three targets (production, staging and testing). I am currently just trying to get the production target working.
I have another view controller where a user clicks a google button and then the action for that button is [[GIDSignIn sharedInstance] signIn]; This takes the user to the Google Plus App and prompts the user to select an account. Once an account is selected, the google plus app then asks the user if my app can access their information. Once a user clicks OK, there is no callback to my app. The user is simply stuck in the Google Plus App. I have a breakpoint in the application openURL method and it never gets hit.
Interestingly enough, if I configure my plist with com-google-gidconsent-google and com.google.gidconsent in the URL schemes with my reverse client id, the application openURL method gets hit but the
[[GIDSignIn sharedInstance] handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
evaluates to NO.
Any help would be greatly appreciated.
Check your application:openURL:sourceApplication:annotation: method, or application:openURL:options: (depends of which one you have in your AppDelegate). Should be something like this implemented for google url scheme
return [[GIDSignIn sharedInstance] handleURL:url sourceApplication:sourceApplication annotation:annotation];
I read that you put in your plist the schemes. But anyway I'll put the xml (plist file) with the urls necessary to configure google plus. The first line, should be what you find in your google developer console in "iOS URL Scheme" with your client ID
<key>LSApplicationQueriesSchemes</key>
<array>
<string>com.googleusercontent.apps.123456789012-abcdefghijklmnopqrstuvwxyz</string>
<string>com-google-gidconsent-google</string>
<string>com-google-gidconsent-youtube</string>
<string>com-google-gidconsent</string>
<string>com.google.gppconsent.2.4.1</string>
<string>com.google.gppconsent.2.4.0</string>
<string>googlechrome</string>
<string>googlechrome-x-callback</string>
<string> https://www.googleapis.com/auth/plus.login</string>
</array>

Integrating a Xamarin app with Facebook SSO w/ Facebook iOS App

I am writing a Xamarin iOS app and having difficulty integrating Facebook SSO, though I don't think my problem is necessarily Xamarin-specific, just a lack of understanding of how to integrate Facebook SSO without the benefit of the Facebook iOS SDK.
I have followed the various guides and have done the following:
1) Have a Facebook App set up:
a) iOS Platform added with bundle id matching my app's bundle id
b) Single sign on enabled
2) Set up my info.plist as follows:
raw text:
<key>CFBundleDisplayName</key>
<string>[company]</string>
<key>CFBundleIdentifier</key>
<string>com.[company].ios.app</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb123490xxx</string>
</array>
<key>CFBundleURLName</key>
<string>com.[company].ios.app</string>
</dict>
</array>
<key>FacebookAppID</key>
<string>123490xxx</string>
<key>FacebookDisplayName</key>
<string>[company] Staging</string>
3) Implemented the following code in my app:
FacebookLoginButton.TouchUpInside += (sender, e) =>
{
var urlWithAppProtocol = new NSUrl("fb123490xxx://");
UIApplication.SharedApplication.OpenUrl(urlWithAppProtocol);
};
I have not overriden AppDelegates methods (OpenUrl and HandleOpenUrl) yet because as far as I can see those handle incoming redirects to my app; I will get that working next.
To be clear, what I'm expecting to see is the FB iOS App equivalent of this screen (from Mobile Safari)
However, if I redirect to:
"fb://[appid]" I get redirected to the FB app but just to the news feed page (or whatever screen I was on last when I was using the FB app)
"fb[appid]://" I get nothing happening, .OpenUrl() does nothing;
"fb://profile/[appid]" as an experiment, I get the following (notice the "app isn't available for your phone"); this could be because you're supposed to use the PageID with /profile.
What am I missing here?
Ok, in the end it was simply using fbauth://authorize in conjunction with the normal query string parameters in the oauth url. The redirect url needs to be fbconnect://success
I found this by reading the source code of the FB iOS SDK:
https://github.com/keithpitt/DKSocial/blob/72cd77bc15ca1a307b92aff8382f2c71a97da7de/External/FBConnect/Facebook.m
There might be a lesson here to use the Xamarin bindings of the official Facebook iOS SDK, which offers this functionality. I've ended up going down the manual route because I started with the Facebook .NET SDK, which doesn't seem to offer this App-based SSO functionality.

Resources