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
Related
I am having trouble figuring out how to switch to Safari from a native app in iOS 7+. I've used UIApplication.sharedApplication.openURL(), but that opens a new tab. I would like to return the user to the current page he/she was viewing before without opening a new tab. I found this SO post, but it is a few years old, so I was hoping things have changed since then.
Here is the workflow I am envisioning:
User taps on a link on an HTML page on Safari to open/install my app
User performs an action on my app
After the user is done performing the action, my app opens Safari automatically, and the user is back on the page where he/she left off
Google has somehow done this with their Google Maps app. If you search for an address on google.com on Safari, you can tap on the map that appears in the search results, and it will open the Maps app. At the top of the Maps app will be a "Return to Safari" bar that you can tap. Once you tap it, you are returned to Safari without loading another tab. I can't seem to find anything regarding how Google did this. If I can replicate that behavior in my app, that would work just fine.
Any help would be greatly appreciated!
There is a way to accomplish what you want using standard iOS APIs. No need to use external components.
You control your webpage and your app, so you know the exact URL that has the link to your app.
These are the steps:
1) In your app, define a custom URL scheme. In this case let's assume you use the scheme myawesomeapp://. You can do this in your Xcode project by going to the Info section of your target. See below
2) In your web page you need to handle the two scenarios: app installed / not installed. It is just a matter of detecting if an app responds to the scheme myawesomeapp://.
To detect from your webpage if your app is not installed please refer to this post
I will explain the case where your app is already installed.
Let's say the webpage that contains the link is:
http://www.mywebsite.com/mypage.html#mytag
The link you provide in your webpage should pass some parameters to the app and one of these should be the URL that you want the app to return. Following with the example the link could be:
myawesomeapp://?action=my_action_1&sourceurl=http%3A%2F%2Fwww.mywebsite.com%2Fmypage.html%23mytag
Note that the URL you pass as a parameter inside the scheme has to be URL encoded or it won't work properly.
3) In your app delegate you need to implement the method:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
In this method, parse the URL, decode the query items and pass the sourceURL to the view controller responsible of handling the action prior to calling it. In this case I set a public property in the ViewController that will store the URL.
#property (nonatomic, strong) NSURL *sourceURL;
4) In the view controller when the user finishes the interaction, you just call:
[[UIApplication sharedApplication] openURL:self.sourceURL];
Because self.sourceURL contains the URL of your webpage, Safari will be launched with the URL. However, because that page is already opened, iOS detects this and re-opens that page.
I have a sample project in my Github page that implements all this.
And to finalize, after you install the sample project in your iPhone, open this stack overflow post from mobile Safari and open my awesome app
Once the app is opened, click on the button and you will return to this stack overflow post.
The behaviour you described is exactly what FB's AppLinks is designed for, and you'll get the same behaviour with all iOS apps that support it (which is quite a lot) out of box!
By the way Google Maps uses the same component: you can see it if you open Google Maps from let's say Fantastical.app!
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.
I am running into a situation which I am not sure is possible from technical/design point of view. Please advise.
Here is what I need:
I have an open URL registered for my native iOS app. I expect a request ID to be passed along with it and once hit I open that request.
From within my native iOS app, I need to open a web page in the webview. This page has few buttons in it.
A tap on the button in the webview should open the request inside my app. So, I want to trigger the registered open URL in step #1.
Web page data is dynamic and will change on the fly.
Is this a feasible design. Shall I consider something else.
Any advise/pointers will be appreciated.
This should be possible. Here's a though:
1: Implement the UIWebview delegate method shouldStartLoadWithRequest.
2: when you intercept that your webview is attempting to access the url yourapp://blah-blah-blah you can return NO instead dip into your appdelegate can manually call the function handleOpenURL.
I've seen something similar in the past with supporting oAuth (I believe it was with instagram) within one of our apps. We basically loaded up the login page in a UIWebview and then when we detected the the post login redirect we parsed the oAuth token from the url and called it good.
Good luck
We are using the legacy headers from the Facebook iOS SDK (3.1.1), as we don't want the user to be able to leave the app. This is a particular issue for us, as we are using GameKit and iOS kills the connection rather quickly after leaving the app (a few seconds is enough)
What I am doing right now, to show the login dialog is:
m_facebook = [[Facebook alloc] initWithAppId:m_fbAppId andDelegate:self];
NSArray * permissions = [NSArray arrayWithObjects:#"publish_stream",nil];
[m_facebook authorize:permissions];
However the dialog doesn't have a cancel button, so the user has no way of leaving it, except with a successful login. Is there a fix?
Best,
Gorm
If you use an older version of the Facebook SDK, the 'X' button will not appear at the top-left of the authorization dialog. Updating to the latest SDK solved the issue for me.
Does anybody know how to place Facebook "like" button into iOS application? I've tried the method described in this blog post. But I do not really like this method, because its ugly Login dialog. And, what is more important, it makes user login twice. For example, user wants post a message to his wall if he isn't logged in I call standard FBLoginDialog, after that user posted a message he may want push "like" button and he have to login again - it is really bad user experience.
How to be? How can I give user "like" feature in my iOS app?
That is actually the only way to do it. There is no special iOS like button. However, the good news is that just today Facebook announced single sign in support for mobile apps. This should remove some of the burden the user faces to log in to facebook.
It seems there is an agreement on not being able to do this. This question shows you can, as does the FB Graph API documentation:
You can comment on or like any object that has a /comments or /likes
connection by posting to https://graph.facebook.com/OBJECT_ID/comments
and https://graph.facebook.com/OBJECT_ID/likes, respectively.
Unfortunately, according to this question you can’t like a page.
I like using ShareKit: http://www.getsharekit.com/
It's not exactly what you're looking for, but still...
The only way supported by Facebook on any platform (web, mobile, etc) is from their iFrame code. From iOS, that means embedding a UIWebView into your application with the iFrame code. Note that it does require them to login via Safari.
- (void)addLikeButton{
[FBSettings enableBetaFeature:TRUE];
[FBSettings enablePlatformCompatibility:NO];
_like = [[FBLikeControl alloc] init];
_like.frame = CGRectMake(60,12,200,33);
_like.likeControlAuxiliaryPosition = FBLikeControlAuxiliaryPositionInline;
_like.likeControlHorizontalAlignment = FBLikeControlHorizontalAlignmentLeft;
_like.objectID = #"https://www.facebook.com/pages/Strana-Gapra/1377227779244834";
_like.likeControlStyle = FBLikeControlStyleStandard ;
[_like addTarget:self action:#selector(onSelect:) forControlEvents:UIControlEventValueChanged];
[self.likeView addSubview:_like];
[self performSelector:#selector(getLikeSubviews) withObject:nil afterDelay:0.6];
}