iOS: Adding a Facebook Like button to a native iPhone app - ios

I would like to know whether it is possible to add a Facebook Like button to a native iPhone app. In the app, the user browses a business directory or deals. When they tap on an item to view the details, it would be nice to have a Facebook Like button that can be used to post the item to the user's Facebook page.
Facebook writes: "Currently, the Like button is only available in mobile web apps".
My app is a native app and not a web app, so therefore I assume it's not possible. However, I do assume that it is possible to mix native UI components on a screen along with web components and therefore it might be possible to implement the Like button, although I am not sure how you pass data from the native portion to the web portion.
If the only solution is a hack, then I won't implement it because at some point the hack will fail when Facebook alters their API.

read around SO a little, you get many leads. Here's one:
Like button in iOS application
And a comment points to github.com/brow/FacebookLikeView
It has same caveats, but it seems there aren't any magic solutions.
There are these blogposts as well:
http://angelolloqui.blogspot.com/2010/11/facebook-like-button-on-ios.html
http://petersteinberger.com/2010/06/add-facebook-like-button-with-facebook-connect-iphone-sdk/
But not sure you get a native UIButton. Maybe you can open a webview in the background and emulate a click on it...
GL, update if you have some findings,
Oded.

Now you can use the FBlike button using the following code but it need to download latest sdk and it is the beta version :(
Here is the code:
[FBSettings enableBetaFeature:FBBetaFeaturesLikeButton];
[FBSettings enablePlatformCompatibility:NO];
FBLikeControl *like = [[FBLikeControl alloc] init];
like.objectID = #"http://shareitexampleapp.parseapp.com/photo1/";
like.likeControlHorizontalAlignment=FBLikeControlHorizontalAlignmentRight;
like.likeControlStyle=FBLikeControlStyleBoxCount;
[self.view addSubview like];

It looks like Facebook finally decided to allow this, more directly, via the Open Graph API.
See documentation here

Check this out, FB just made it possible through their SDK. Only for testing and ios for now
https://developers.facebook.com/docs/ios/like-button/

Related

Show preview of URL while entering a link in UITextView

I need to show a preview of a URL (like FB and WhatsApp do), while the user is entering a link in a UITextView.
Is there a library on iOS to grab it, or do we have to make our own?
Thanks in advance.
iOS does not provide this functionality by default.
You will have to build your own or use an open source solution.
This project might provide what you need:
https://github.com/itsmeichigo/URLPreview

SFSafariViewController requesting to Open YouTube App when YouTube is installed

I have an iOS 9 only app which I am developing with a UITableViewController and a list of videos by a company. Some of the videos are hosted on YouTube. In the didSelectRowAtIndexPath, I implement the use of SFSafariViewController in the following way:
SFSafariViewController *safariVC = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:#"https://www.youtube.com/watch?v=YQHsXMglC9A"]entersReaderIfAvailable:NO];
safariVC.delegate = self;
[self presentViewController:safariVC animated:YES completion:nil];
Please note, the video in that link is not the video I am using for my app - it's simply an example.
When I click that without the YouTube.app installed on my device, it opens up in SFSafariViewController. If I have YouTube.app installed, it prompts me to open the link in there:
I understand why this is happening, because of the work in iOS 9, but how can I prevent it? It'll be pretty annoying for my users to have to go to YouTube to watch the video and then come back to the app (even if it's via the back link at the top).
How can I prevent this from happening within the app, to say use the SFSafariViewController within the app rather than the YouTube app?
Update
This behaviour does not happen with the Twitter or Facebook native apps, so the question is, is this a YouTube native app issue (something I can't do anything about) or is there a way for me to prevent the opening? With SFSafariViewController, Apple's aim would have been to make it easier; there must be a way to prevent apps from prompting and loading in the native app.
Any guidance on this would be appreciated.
I don't see a delegate to do this. I guess this is the native behavior and exactly what you get with a SFSafariViewController. You COULD recreate a 'light version' by using a WebView directly instead

Get referrer string for Universal Link?

I implemented Universal Links in our iOS 9 app and they work by calling a method in AppDelegate.swift, in which I get an NSUserActvity with an URL attached to it.
Is there a way to get the (HTTP-) referer? I need to know on which website the user has tapped the link that opened the app.
You should be able to use NSUserActivity > referrerURL instance property. See https://developer.apple.com/documentation/foundation/nsuseractivity/2875762-referrerurl.
No, there is no way to get the referrer.
An Apple employee made that pretty clear on the developer forums: https://forums.developer.apple.com/thread/65423
They say that the only way to get some kind of referrer would be to append it to the URL. Maybe take a look Google's campaign tracking URLs (utm_...).
I found another interesting solution if you need to support iOS 9 and 10 - https://appmetrica.yandex.com/blog/referrer-based-tracking-dlya-ios-tochnaya-atributsiya-dlya-lyubogo-istochnika-trafika.
Since iOS 11 I guess can be used NSUserActivity > referrerURL.
In short:
SFSafariViewController uses the same cookies as Safari app.
You can open invisible SFSafariViewController inside your app.
If your site contains some cookie - use Universal Link to pass it back to the app.
Though it requires to implement something like tracking link on your site.

FBRequestConnection does not provide UI while FBDialog Does

I am using FBRequestConnetion to post[only text] on the wall. But, the problem there is deprecated class in latest FacebookSDK , which is FBDialog.
So, Is there any other UIComponent in latest FacebookSDK, through which I can achieve the FBDialog Behaviour to post on the wall.
Or I have to design my own UI and use FBRequestConnection.
I'm confused about this too. Looking at the HelloFacebookSample sample from the SDK, that's what I understand:
In the previous SDK, we could display a dialog where the user can customise the message, and choose to post or cancel. I think this didn't require any special Facebook permissions.
Now iOS6 has a nice native dialog, but the iOS5 fallback is to post directly using FBRequestConnection - which just posts directly without any dialog, and also requires the "publish_action" permission.
I guess I arrived at the same conclusion, if we want a nice dialog on iOS5, we have to:
create the UI ourselves (maybe imitating the IOS6 popup) and ask for the new permission
or use the deprecated headers in the SDK folder (not sure I'd go there...)
Take a look at SDK that was just released + this link for a a native UI built on top of iOS6:
https://developers.facebook.com/docs/howtos/ios-6/
You can also look at the updated sample HelloFacebookSample that's included in the SDK that shows how you can post a status update for a user.

Like button in iOS application

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];
}

Resources