How to share a link on Facebook Messenger from other apps? - xcode

From Facebook Developer Documentation, I see that I can share image, animated image, even audio clips from other app to Facebook Messenger. But I can see no way to share a link. Neither does when I try to look what kind of share does the FBSDKMessengerShare offer.
How can I share a link using Facebook Messenger?

Seems that it can't be done with FBSDKMessengerShare, but with FBSDKShareKit it's possible. (I'm using Xcode 8.3, Swift 3.1, Cocoapods with FacebookShare 0.2.0)
More info available at
https://developers.facebook.com/docs/sharing/ios
There are two methods:
Using FBSDKMessageDialog:
"The Message Dialog switches to the native Messenger for iOS app, then returns control to your app after a post is published."
#IBAction func messengerButtonAction(_ sender: UIButton) {
let linkContent = FBSDKShareLinkContent()
linkContent.contentURL = URL(string: "https://itunes.apple.com/in/app/someValidAppURL...")
let dialog = FBSDKMessageDialog()
dialog.shareContent = linkContent
dialog.shouldFailOnDataError = true
if dialog.canShow() {
dialog.show()
}
}
Using FBSDKSendButton: "The Send button lets people privately send photos, videos and links to their friends and contacts using the Facebook Messenger. The Send button will call a Message dialog."
This creates a share button that is displayed in a specified view. The button will be automatically disabled if the Messenger app is not installed on the device.
override func viewDidLoad() {
let linkContent = FBSDKShareLinkContent()
linkContent.contentURL = URL(string: "https://itunes.apple.com/in/app/someValidAppURL...")
let button = FBSDKSendButton()
button.shareContent = linkContent
if button.isEnabled {
self.view.addSubview(button)
}
}

Related

How to preserve split view divider configuration in Mac Catalyst app?

Mac apps that have a sidebar (Mail, Finder, etc) allow you to resize its width, and that width is preserved across app launches. You enable this behavior in an AppKit app by assigning autosaveName on your NSSplitView. How do you do this in a Mac Catalyst app using UISplitViewController?
By default, my Catalyst app's sidebar is pretty wide, so every time the user opens it they have to resize it.
I reached out to a friend who was able to achieve this in their app. They said you can manually save the current width to UserDefaults and upon creating the split view controller set its preferredPrimaryColumnWidth to the last saved width. Nice!
In my UISplitViewController subclass I added:
init() {
let lastWidth = UserDefaults.standard.integer(forKey: "SidebarWidth")
let initialWidth = lastWidth > 0 ? CGFloat(lastWidth) : 220
preferredPrimaryColumnWidth = initialWidth
//...
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
UserDefaults.standard.setValue(Int(primaryColumnWidth), forKey: "SidebarWidth")
}

UIActivityViewController display is scrolled in last iOS11 GM on iPhone7Plus

Since the last release of iOS11 (GM version), the activity view is displayed scrolled to the top, with a spring resistance preventing the user to 'unscroll' it.
Previous version of iOS 11 (beta version) never suffered from this, nor iOS 10.
Also, one can see a blank margin at the bottom plus the fact that the preview image is not fetched/displayed right in the Website preview.
Here is the code. Any idea?
let textToShare = "\(message) (\(share))"
let objectsToShare : [Any] = [textToShare, url]
let activityViewController = UIActivityViewController(activityItems: objectsToShare as [AnyObject], applicationActivities: nil)
// New Excluded Activities Code
activityViewController.excludedActivityTypes = [.airDrop, .addToReadingList]
activityViewController.completionWithItemsHandler = {
(activityType: UIActivityType?, completed: Bool, returnedItems: [Any]?, error: Error? ) -> Void in
_completed(completed)
}
Ok. It’s only Twitter app itself that had to be updated for iOS11 (as in iOS11, there is no longer centralized system, sharing is handled by apps such as Facebook or Twitter themselves).

Xamarin Forms: Native Embedding Android and iOS Video Player

I've been working on this Xamarin Forms mobile application and I've been loving it but it's a media player application and the native embedding for the platform specific video player doesn't work. After much debugging I was able to get the audio playing but no video would show up. I think this has to do with the views just not being swapped out appropriately. Unfortunately there isn't much material on how to effectively switch from a Xamarin Forms view to a native view (to see the video) through Xamarin Forms. Any help is appreciated thank you !
I was able to get iOS videos working by using the Xamarin Forms messaging service to Appdelegate class and built the AVPlayer class there. Works great.
playVideo.Clicked += (sender, e) =>
MessagingCenter.Send(this, "ShowVideoPlayer", new
ShowVideoPlayerArguments(videoUrl));
Appdelegate.cs
MessagingCenter.Subscribe<VideoDetailPage,
ShowVideoPlayerArguments>(this, "ShowVideoPlayer",
HandleShowVideoPlayerMessage);
//messaging center class
private void HandleShowVideoPlayerMessage(Page page,
ShowVideoPlayerArguments arguments)
{
var presentingViewController = GetMostPresentedViewController();
var url = NSUrl.FromString(arguments.Url);
var avp = new AVPlayer(url);
var avpvc = new AVPlayerViewController();
avpvc.Player = avp;
avp.Play();
presentingViewController.PresentViewController(avpvc, animated: true,
completionHandler: null);
}
private UIViewController GetMostPresentedViewController()
{
var viewController =
UIApplication.SharedApplication.KeyWindow.RootViewController;
while (viewController.PresentedViewController != null){
viewController = viewController.PresentedViewController;
}
return viewController;
}
However.. Getting this to work with Android is a whole different animal since I have to have deal with .axml layouts I believe.. Any help with this would be greatly appreciate.. Thanks so much guys.
So I figured out an implementation using Native Views, an alternative to Custom Renderers. Such a more stream lined process.

Swift 2 Is it possible to add a web link to an annotation callout?

I'm able to create pin's with their popup's as well as the info-light button to the right. And when tapped, the info button pops up an alert with some text and an "ok" button at the bottom. Is it now possible to add a link at the bottom of the text that will direct the user to a URL, saw wikkipedia for example in safari?
I've used the following called function to succesfully do so with a regular button in the mapview, but I can't figure out how to implement it the way I've stated above
#IBAction func webLink(sender: AnyObject) {
if let url = NSURL(string: "http://www.wikipedia.com") {
UIApplication.sharedApplication().openURL(url)
}
}

WKWebView Cache manifest not working IOS8

Cache manifest works fine and events fired in safari in IOS 8. Not working at all in WKWebView anyone else solve this issue?
import UIKit
import WebKit
class ViewController: UIViewController {
#IBOutlet var containterView : UIView! = nil
var webView : WKWebView?
override func loadView(){
super.loadView()
self.webView = WKWebView()
self.view = self.webView!
}
override func viewDidLoad() {
super.viewDidLoad()
var url = NSURL(string:"http://html5demos.com/offlineapp")
var req = NSURLRequest(URL:url)
self.webView!.loadRequest(req)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
The application cache comes back as supported if I were to use html5test.com
EDIT:
window.applicationCache does not return undefined either when loaded from WKWebView
console.log("Initializing Page");
if (window.applicationCache == undefined){
console.log("Application cache not suported!");
updateSplash();
}
console.log(window.applicationCache); returns: DOMApplicationCache
EDIT 2:
if (typeof window.applicationCache.update === 'function'){
console.log("Application has method update");
console.log(window.applicationCache.update); //shows swapCache() and update() methods
window.applicationCache.update();
}
window.applicationCAche.update() throws Error: InvalidStateError: DOM Exception 11: An attempt was made to use an object that is not, or is no longer, usable.
Just for the record, this question appears to have been asked on and linked from the Apple Developer Forums. The official response from Apple is that the HTML5 Application Cache functionality is not available in WKWebView:
The offline application cache is not enabled in WKWebView. Feel free to request that it be made available via https://bugreport.apple.com.
I think you are trying to solve the same problem as I do. This is what I do.
Save the start page of your web app into one HTML file(index.html), embedding everything (CSS, JS, images as base 64, icon fonts). And add that file into your Xcode project.
Start the app by reading the content of the HTML file and load it in your WKWebView. You can set the base as the same url you are supposed to start with. This way, it'll be as if the web app is opened on your web site.
The benefit is that your app will always start even when the user's network isn't good. Here's the SWIFT code that I use, courtesy of Matt Neuberg (https://books.google.com/books?id=wLaVBQAAQBAJ&pg=PT669&lpg=PT669&dq=addConstraints+wkwebview&source=bl&ots=7trE7MR1zR&sig=VT6GDBGbDw9dh89wDb5Uajd4gUY&hl=en&sa=X&ei=cyyeVNH4MM3ToATukoDgAQ&ved=0CDkQ6AEwBA#v=onepage&q=addConstraints%20wkwebview&f=false). If you want the full source code, please let me know and I'll post it on Github.
let templatepath = NSBundle.mainBundle().pathForResource("index", ofType: "html")!
let base = NSURL(string:"http://m.ftchinese.com/iphone-2014.html#iOSShare")
var s = NSString(contentsOfFile:templatepath, encoding:NSUTF8StringEncoding, error:nil)!
self.webView!.loadHTMLString(s, baseURL:base)

Resources