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
Related
I've had an issue on my app overnight that I thought was a coding bug. The issue is that the SFSafariViewController login window (Safari based) - is no longer being presented. Instead, it is launching a new Safari app, and once I log in, I now get the native iOS dialog "Open his page in "XXXXXApp"? I didn't change any settings, didn't play with anything at all. After downloading the source for the FSBDK iOS and debugging, it turns out that "SFSafariViewController" is being disabled by facebook explicitly.
I made a graph call, the same one that the app uses to start up to this endpoint:
https://graph.facebook.com/v2.7/<app-id>?fields=app_events_feature_bitmask%2Cname%2Cdefault_share_mode%2Cios_dialog_configs%2Cios_sdk_dialog_flows.os_version%289.3.0%29%2Cios_sdk_error_categories%2Csupports_implicit_sdk_logging%2Cgdpv4_nux_enabled%2Cgdpv4_nux_content%2Cios_supports_native_proxy_auth_flow%2Cios_supports_system_auth%2Capp_events_session_timeout&format=json&include_headers=false&sdk=ios
And the response appears to disable the controller SFSafariViewController. The evidence in this portion of the payload:
"ios_sdk_dialog_flows": {
"default": {
"use_native_flow": true,
"use_safari_vc": false
}
}
Previously, the use_safari_vc value was set to true. In anyone answers, please keep in mind I want to use the Safari View Controller - but not launching safari as it falls back to now. The latest behaviour asks to open my app, which I thought the Safari View Controller was meant to solve! Also keep in mind that everything was functioning well until this morning. I've tried recreating my app multiple times, but the same behaviour still persists.
Help, my user experience with Facebook is now terrible (and note, I don't care about using native behaviour - I just want Safari View Controller again!)
I'm using v4.15.0 of the Facebook SDK
Cheers
I got word from Facebook developers group that it was an issue on the server side, and that change has been reverted.
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!
In my app I'm using the following code that allows to share an image with a text:
- (IBAction)sharePressed:(id)sender {
UIImage *postingImage = [UIImage imageWithContentsOfFile:self.filepath];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[#"Lorem ipsum", postingImage] applicationActivities:nil;
[self presentViewController:activityViewController animated:YES completion:nil];
}
Posting the image to Facebook works fine and it appears on my FB wall, however in my console I get the following message:
plugin com.apple.share.Facebook.post invalidated
I've tested it on a couple of devices, as far as I could see it only happens on my iPhone 6 with iOS 8.1 installed.
Anyone knows what that message means and how to prevent it from showing?
Here is the correct answer ios plugin com.apple.share.Facebook.post do not show provided text. It's a bummer.
I'm afraid to tell you, you cannot post text to Facebook programatically. It's a new Facebook prohibition that forbids "pre-filled" Facebook sharing. That is why newer versions of iOS do not show your text, even tough it's correctly provided (and works on Twitter and in other sharing options).
For more info please refer to https://developers.facebook.com/docs/apps/review/prefill
This is a terrible error message by Apple. Go to settings and check your facebook/twitter accounts. You will notice they have no password set (perhaps this happens after updating to 8.1). Just update the account info and the message will be gone and your post/tweet will work.
In my case, this is related to the fact that the Facebook app replaces the iOS system level Facebook share extension with a custom one. Case is triggered as follows:
Load an app and share to Facebook (Note: Facebook app is currently
installed)
Exit app
Delete the Facebook app from device
Open app again (still active in memory) and share to Facebook ...
fail! The app is looking for a share extension that was
uninstalled along with the Facebook app
Kill and restart the app, share to Facebook. Voila! The app has loaded the default iOS Facebook share extension and it works again.
Head scratcher as to why Apple let Facebook take this approach as opposed to either forcing them to replace the default Facebook share extension or just not allowing them to inject their own, only if their app is installed.
It also happen when u try to set an URL using addURL: method for SLServiceTypeTwitter in your SLComposeViewController. Deleting it fix the issue.
Facebook has updated their policy. It doesn't work with this anymore. you need to integrate Facebook sdk to do so. here is the relevant references for those who want to share image or post from your app to Facebook
https://developers.facebook.com/docs/sharing/opengraph/ios#sharedialog
I faced the same issue. I was using activity controller and SLComposeViewController, and in both cases got the same error, even if i don't set any text/url etc for fb programatically. So according to me, in my case, it was not the issue of new facebook policy as mentioned in comment above.
To avoid any inconvenience in future, i fixed it by using facebook share SDK (not using SLComposeViewController or activityViewController now). FBSdk is integrated in my iOS project and the code, i used for sharing purpose is as:
#IBAction func shareOnFaceBook(sender: AnyObject) {
var content = FBSDKShareLinkContent()
content.contentURL = urlToShare() //method returning the url
content.contentDescription = textToShare() //method returning text(string) to share
var dialog = FBSDKShareDialog()
dialog.mode = FBSDKShareDialogMode.Automatic
dialog.shareContent = content
dialog.delegate = self
dialog.fromViewController = self
dialog.show()
}
It'll open fb application (if installed), Otherwise will open Safari (fb web application).Hope that it'll help you
Best,
I wanted to open Facebook and Twitter apps from my app. I find very simple way like:
NSURL *url = [NSURL URLWithString:#"fb://profile"];
[[UIApplication sharedApplication] openURL:url];
And there are many others url for open different page of Facebook. How can I check if Facebook app exist on iPhone? What happens if the application is not install on device? Now I try to use this method on iOS Simulator but nothing happened. It's bug of iOS Simulator? Only tomorrow I will have chance to check on device.
You can check if a URL would likely open ahead of time using the canOpenURL method of UIApplication.
http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/instm/UIApplication/canOpenURL:
Also! You can pass values for the facebook page you'd like. This Stack Overflow includes a link to a wiki with all the variations:
Launching Facebook and Twitter application from other iOS app
If you know the URL scheme that the other app is using (e.g. fb:// for the Facebook app), you can first ask whether your UIApplication object can open such URLs in the first place, with canOpenURL:. You can use this, for instance, to decide whether to display a link at all, or whether to direct the user to Safari (with a normal web URL) instead.
As third-party apps cannot be installed on the Simulator as far as I know, the only way to test compatibility with them is on an actual device.
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/