Handling event on click of a browser item? - ios

I have to do facebook like onclicking of a button in ViewControler . It should like our page on the back end automatically as we see in many website.
I didn't find a better solution but still i open my facebook page onclick. and the user can manually like the page in the browser. Now i want to handle whether user like that page or not in browser.
Simple Words
When user like my page i have to save it in my database whether he likes my page or not. I open my facebook page on button click . It opens in a webview or browser, User may not like my page and press back button how could i know whether he likes my page by enabling Javascript or check some other way that the button is clicked or not.
It would be very helpful if someone told me how to directly like our page automatically onclicking of a button in IOS.
I know WebView delegate: shouldStartLoadWithRequest
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
if (navigationType == UIWebViewNavigationTypeLinkClicked){
NSURL *url = request.URL;
[self openExternalURL:url];//Handle External URL here
}
return YES;
}
but there are multiple button how to distinguish between those button. or i mean how i know that like button is clicked..

Take a look here: Facebook like
You need to have publish_actions permissions. The graph url for this is: https://graph.facebook.com/[User FB ID]/og.likes?object=OG_OBJECT_URL&access_token=USER_ACCESS_TOKEN
However, you cannot use this to like a page on Facebook currently, as the documentation states:
For Facebook Pages or websites that do not integrate with Facebook
Authentication, developers should continue to use the Like button
social plugin.

Related

Is it possible to invite friends without showing Facebook dialog?

I am building an iOS app that is using facebook to gain traction. I would like to invite some friends, that user selects from list, but without showing facebook confirmation dialog, i want that to happen behind the scenes.
Reading documentation there is property frictionlessRequestsEnabled, but even that shows dialog, where i have option to disable showing dialog in the future. Is there some other way to do this?
Many apps invite all of your friends without showing the Facebook Dialog Box. It is possible by modifying the FBSDK. Simply clone the FBSDK repository to your local machine, edit in Xcode and Command+B to build the framework for your own use. The following classes are relevant to inviting in the FBSDK for iOS:
FBSDKWebDialogView
FBSDKWebDialog
FBSDKGameRequestDialog
To get the URL Generated for the dialog view:
In FBSDKWebDialog.m in -(BOOL)show:
NSURL *URL = [self _generateURL:&error];
This is the URL generated to load the web view. It is possible to use this URL without the web dialog view, as long as it is only generated once (access token gets reset every time the URL is generated) and is used on a mobile browser.
To Invite Without The Dialog Box
You can use javascript to simulate clicking the go button by doing something like this (assuming you have specified your parameters and recipients properly and your app is already set up through Facebook)
In FBSDKWebDialogView.m in - (void)webViewDidFinishLoad:(UIWebView *)webView :
[NSTimer scheduledTimerWithTimeInterval:.1 target:[NSBlockOperation blockOperationWithBlock:^{ NSString * jsCallBack = [NSString stringWithFormat:#"document.getElementById(\"u_0_0\").click();"];
[webView stringByEvaluatingJavaScriptFromString:jsCallBack];
[webView stringByEvaluatingJavaScriptFromString:#"document.getElementById(\"u_0_0\").click();"]; }] selector:#selector(main) userInfo:nil repeats:NO ];
As long as the webView is present somewhere, you may be able to do these actions with little interference for the user. You could set the webView frame to be very small, or potentially hide the view altogether.
Facebook is however, policing hard against this sort of thing and it likely that that there will be more protection against this in the future.
FBSDK Repo Here:
https://github.com/facebook/facebook-ios-sdk

Social Media Login in UIWebView

In my iOS app, I am opening a URL in a UIWebView. On the webpage, there is an option to login through social media like Facebook, Google, Twitter etc.
But when I click on the login through say Facebook option, I see a blank screen. What happens is that, it opens a pop-up in the same UIWebView instance. But I am not sure why I see a blank screen.
The URL works well if I use Safari on my device.
Can you please guide what options on UIWebView shall I enable that the pop-ups work. Also I feel that the pop-up(for FB Login) will throw a callback on the initial page. So please help me how should I handle the call back.
Thanks!

How can I know the URL that the user clicked on while the page is loading?

Sometimes we click on links before the page has fully loaded. It turns out that there’s no reliable way of knowing what the link that the user click is. You might say that it’s safe to look at the delegate method:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
But, as some of my experiments have shown there are calls to this method with UIWebViewNavigationTypeLinkClicked more than once for the same page.
For example, try logging this path:
Go to google.com.
Search for "new york times".
Click on the first link.
At step (3) the delegate get’s called 3 times! with UIWebViewNavigationTypeLinkClicked. First, when you click the link to go to nytimes.com from google and then two more times while it’s loading. In-sane!
I’ve gone to the extreme for this. I remade my entire project in iOS 8 hoping that the new WKWebView would provide a solution but it turned out it worked the same way.
I figured out a solution but I really can’t tell wether it will work or not every time the user clicks a link while the page is loading.
Here it is:
When you click a link to go to another page the delegate get’s called with this method:
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;
The error is:
"The operation couldn’t be completed.” (-999)
The last link that the UIWebView loads before the error is thrown is the new link that the user clicked on. So, if you store every link that the UIWebView loads in a variable named lastURL you can use the lastURL as the new page’s URL.
Two things I worry about:
The delegate get’s called to report the error with a slight delay allowing a few sub frames of the new web page to load resulting in the lastURL to store the URL of some sub frame of the new link and not the actual new link.
The error -999 is thrown for some other issue and not when the page has failed loading because the user clicked a link.
Is there a more reliable way? I don't care if your way works for iOS 7 or iOS 8.

Facebook login in unity iOS game without redirect

In my game I use for login in Facebook
FB.Login("email,publish_actions,user_games_activity", LoginCallback);
When I click on button, Safari browser pops up for a second and then redirects me back to my app without connecting me to Facebook. I need without redirect authorization and popups
How can I do that?
1) Locating Facebook/Editor/iOS/FbUnityInterface.mm
2) Find method -(void)login:(const char *)scope { ... }
3) change
openWithBehavior:FBSessionLoginBehaviorWithFallbackToWebView
to
openWithBehavior:FBSessionLoginBehaviorForcingWebView
4) now, each time you request login, an embed web-view dialog will be popped out instead of jumping out of current game to Facebook login dialog.

Invoking Safari on iOS without opening a new website

The situation is like this:
User opens app from a website using a custom urlscheme
User does stuff in the app
User clicks button in the app to return to the website in Safari.
I have tried opening a new tab containing a javascript:window.close() but this does not work on iOS 6.1.
So my question is: Is there a way to open Safari to view the website the user left from? Either with a working new tab that closes itself or a different route?
When you open the app with your custom url scheme, pass the actual page url as an argument.
mycustomUrlScheme://mydomain.com?objectid=1234&callback_url=encoded_url
In your app, handle the url for the content info and keep the page url to open it afterwards. It will make safari open a new tab. But that should be a good start.
As far as i understand you can do it.
user opens mobile safari for example http://www.example.com
user clicks a link that is appscheme://open and the application become active
user taps a button to open safari for example http://www.example.com?q=test
for the third step you can use [[UIApplication sharedApplication]openURL:url]

Resources