Sending an animated Gif via sms in Swift - swift

I'm trying to send an animated gif via the MFMessageComposeViewController in swift,
It seems to be working fine when I send the gif, however the preview shows a non-moving image. Any thoughts on how to make the preview animated?
let messageComposeVC = MFMessageComposeViewController()
let imgData = NSData(contentsOfURL: NSURL(string: "http://dramallamaapp.com/wp-content/uploads/2016/08/output_9GECbQ.gif")!)
if imgData != nil {
messageComposeVC.addAttachmentData(imgData!, typeIdentifier: "com.compuserve.gif", filename: "animated.gif")
}
messageComposeVC.messageComposeDelegate = self
presentViewController(messageComposeVC, animated: true, completion: nil)

Upon further investigation, I now believe this is default iOS behavior, as with iMessages the same happens (gif shows as an image until sent, then begins animating).

Related

Using an AVPlayer returns a "non-Multipath connection" error

I'm using AVKit to play a youtube URL.
I have this code inside a button action:
#IBAction func trailerButtonAction(_ sender: Any) {
guard let youtubeUrl = youtubeURL else { return }
let player = AVPlayer(url: youtubeUrl)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
present(playerViewController, animated: true) {
player.play()
}
}
The URL is valid, but when I press the button, the video doesn't stop loading and I'm getting this message on Debug area:
nw_endpoint_flow_copy_multipath_subflow_counts Called on non-Multipath connection
Edit:
I found that AVPlayer doesn't support youtube URL
I would say this log isn't necessarily relevant. I was getting this error when trying to playback on the simulator but it wasn't happening on a real device.
One workaround would be to use a 12.4.x simulator as it does not exhibit this issue. Only the 13.x simulators are showing this error. It happens to repeatedly that it slows down Simulator to a craw until all requested tracks have been buffered.
To combat this while testing, I am either not turning on AVPlayer or I am only buffering a short track.
To cut down on the number of errors try initing your AVPlayer like so:
var avPlayer : AVPlayer = AVPlayer()
This may cut down the errors by 30%.

UIActivityViewController - Can't AirDrop a more than one object type simultaneously

I'd like to be able to AirDrop a text file and an image at the same time using the UIActivityViewController. The code below works fine to send both file types via iMessage or eMail, but it fails when I try to use AirDrop. The code works fine for AirDropping 2 images or 2 text files, but not for one of each.
#IBAction func shareImage(_ sender: UIButton)
{
// can't seem to AirDrop a mixture of file types. ie. can send 2 images, or 2 data files, but not an image and a data file
let fileToSend: NSURL = NSURL(fileURLWithPath: dataFile!)
let image = imageView.image!
let objectsToShare = [fileToSend, image] as [Any]
let controller = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
controller.excludedActivityTypes = [UIActivityType.postToFacebook, UIActivityType.postToTwitter, UIActivityType.postToWeibo, UIActivityType.print, UIActivityType.copyToPasteboard, UIActivityType.assignToContact, UIActivityType.saveToCameraRoll, UIActivityType.postToFlickr, UIActivityType.postToTencentWeibo]
self.present(controller, animated: true, completion: nil)
}
AirDrop to an iOS device does not support sending multiple different types, but sending to a mac does. Until Apple changes that there is no code change that you can do to "fix" this.

How Add UIActivity Indicator on ImageView in swift using Alamofire Image

I am Using AlamofireImage library and i want to add a subview (UIActivityIndicator) on ImageView until image did not download. but have no idea how to do it.
self.imgView_main.af_setImageWithURL(downloadURL)
image is downloading. but how to show UIActivityIndicator please help me
You can use completion: function for that, First start the activityIndicator and stop the indicator when you get the image in completion block like this.
self.activityIndicator.startAnimating()
self.listImageView.af_setImageWithURL(
NSURL(string: list!.image!)!,
placeholderImage: nil,
filter: nil,
imageTransition: .CrossDissolve(0.5),
completion: { response in
let image = response.result.value // UIImage Object
self.activityIndicator.stopAnimating()
}
)

Swift SafariViewController animation

In my SpriteKit games, all in landscape, I am showing a SafariViewController.
func showSafariViewController(forURL url: String) {
guard let validURL = NSURL(string: url) else { return }
let safariViewController = SFSafariViewController(URL: validURL)
safariViewController.delegate = self
// present safariViewController
}
The open/closing animation is from the right side.
When using the Facebook SDK to login with Facebook it looks like they are using a SafariViewController as well and it animates in/out from the bottom.
Is there a way I can achieve this as well?
FacebookSDK behavior is a little bit tricky: they added SafariVC to another view controller (containerVC) and then present containerVC, not SafariVC.
I write an example that implements this behavior (not sure about autoresizing mask, may be you need to use autolayout, but it is up to you):
let containerVC = UIViewController()
let url = URL(string: "https://yandex.ru")!
let safariVC = SFSafariViewController(url: url)
containerVC.addChildViewController(safariVC)
safariVC.view.autoresizingMask = [ .flexibleWidth, .flexibleHeight ]
safariVC.view.frame = containerVC.view.frame
containerVC.view.addSubview(safariVC.view)
safariVC.didMove(toParentViewController: containerVC)
self.present(containerVC, animated: true, completion: nil)

UIActivityViewController - Facebook, works perfectly on simulator, but not on a device

When I run through the Xcode simulator, I can post both a picture and a url. One a device, however, I get an entirely different dialog.
I've used another example on here to illustrate the code
let myWebsite = NSURL(string:"http://www.google.com/")
let img: UIImage = imageView.image!
guard let url = myWebsite else {
print("nothing found")
return
}
let shareItems:Array = [img, url]
let activityViewController:UIActivityViewController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
activityViewController.excludedActivityTypes = [UIActivityTypePrint, UIActivityTypePostToWeibo, UIActivityTypeCopyToPasteboard, UIActivityTypeAddToReadingList, UIActivityTypePostToVimeo]
self.presentViewController(activityViewController, animated: true, completion: nil)
On the simulator, the dialog comes up perfectly, and it posts both the picture and url to Facebook.
When I run the exact same example on my phone, a totally different dialog comes up, where I'm asked to add a line ("say something about this") and then it posts this headline, along with the google url
Interestingly enough, on the simulator, the url is posted as a url in Facebook, on the device, it's posted as a hyperlink.
Ultimately, I would like the the image and the hyperlink to appear on Facebook. However, if I was able to get the image and the url to post, I would be thrilled.
Has anyone had similar experiences?