How to display images from Photo gallery on uiwebview ios swift? - ios

Using Photos API(PHImageManager) i am able to get list of photos url and photo object.
When I am trying to use that url in webview , image is not displaying
Consider the following image url which I got from Photos API(PHImageManager)

you just have to take that burl in string and then load that string in webview in viewdidload
like
urlStr = obj["url"] as! String
and then load that url in uiwebview
webview.loadRequest(NSURLRequest(URL: NSURL(string: urlStr)!))

Related

SDWebImage doesn't show locally stored image on a real device but it shows up in simulator

I'm using SDWebImages library to get image for thumbnails. It is working seemlesly.
However when I navigate from video to a controller where I play video, I need to show thumbnail once again. I need an image path to pass to the player.
The problem is if I pass the same URL the player will download the image once again. In order to avoid this behaviour i'm trying to get the image from disc which is already stored there by sdwebimages library.
/// get thumbnail from cache
var thumbnail: String?
if (video?.hasThumbnail) {
let urlString = "https://test.com/image/001.png"
if let path = SDImageCache.shared.cachePath(forKey: urlString) {
thumbnail = path
} else {
thumbnail = urlString
}
}
This is working on a simulator, but NOT on the real device.
Please read more about how to use
imageView.sd_setImage(with: URL(string: "http://www.example.com/path/to/image.jpg"), placeholderImage: UIImage(named: "placeholder.png"))

Webview Not Refresh Image

I am Load Html File to webview using load html string method. All works fine. in my code user choose image as profile and choosen image save on fix path and name. when user choose image and when web view reload at that time image show old image. image updated to directory but not show.
This problem only occure in Ipad, In Iphone work fine.
Have any Suggestion.? then please suggest
//My Loading Code
webview.loadHTMLString(invoiceHTML, baseURL: NSURL(string:resumeComposer.HTMLFilePath)! as URL)
//Image Source update to HTML String code
imgPath = URL(fileURLWithPath: folderpathforNormal).appendingPathComponent("ProfileImg.png").path
HTMLContent = HTMLContent?.replacingOccurrences(of: "*userimage*", with: imgPath)
clear the UIWebview cache first like this:
//to remove cache from UIWebview
URLCache.shared.removeAllCachedResponses()
if let cookies = HTTPCookieStorage.shared.cookies {
for cookie in cookies {
HTTPCookieStorage.shared.deleteCookie(cookie)
}
}

how to display and where to display a pdf file by considering filePath in swift 3?

I am new to iOS development. In my project i am displaying a exerciseFilePath on tableview.
the response is given below.
"exerciseId" : 1,
"exerciseName" : "Fitness Exercise",
"exerciseFilePath" : "\/p\/pdf\/exercise_pdf\/fitness_exercise.pdf"
i need to display the pdf in another view on didSelectRowAtIndexpath.
i Dont know how to display the pdf and what are steps to be followed to display that pdf.
I hope you understand my problem. please help me how I can do this.
Why don't you use QLPreviewController or UIDocumentInteractionController?
Now in your case you can do it by using webView:
let req = NSURLRequest(url: pdf) //pdf is your pdf path
let webView = UIWebView(frame: CGRect(x:0,y:0,width:self.view.frame.size.width,height: self.view.frame.size.height-40)) //Adjust view area here
webView.loadRequest(req as URLRequest)
self.view.addSubview(webView)
Some tutorials:
QLPreviewController example
UIDocumentInteractionController example

How to post a video selected from the library on an apple device to a view controller in xcode using swift

I would like to choose a video from the library(which I have completed) NOW, I want to take that video and display it in a view controller. What do I do? I have looked everywhere and have found nothing.
Here is my code for trying to get the file name of a selected video from the library, which I am trying to display in a webview. It does not work.
videoURL = info[UIImagePickerControllerReferenceURL] as! NSURL?
let fileURL = NSURL(fileURLWithPath: " (videoURL)")
videoView.loadHTMLString( " ", baseURL : nil)
Any help is much appreciated. Thanks!
You'll need to implement the delegate methods.. Check this out:
How to select any Video or Movie file from UIImagePickerController

How to convert a video NSURL to an ALAsset?

Facebook sharing requires an ALAsset such as the following:
let content = FBSDKShareVideoContent()
//The videos must be less than 12MB in size.
let bundle = NSBundle.mainBundle()
let path = bundle.URLForResource("a", withExtension: "mp4")
let video = FBSDKShareVideo()
// doesn't work; needs to be an "asset url" (ALAsset)
//video.videoURL = path
content.video = video
let dialog = FBSDKShareDialog()
dialog.shareContent = content
dialog.show()
How is it possible to take a local bundle document, or an NSData object, and convert it to an ALAsset?
(My initial thinking was saving the video to the local camera roll, and then loading the list and selecting it, but that is unnecessary interface steps)
The documentation for an ALAsset states that
An ALAsset object represents a photo or a video managed by the Photo application.
so I'm pretty sure that you have to write the video to the camera roll before using it as an ALAsset. However, you don't need to open the camera roll and have a user pick the asset in order to use it. When writing to the ALAssetLibrary using
library.writeVideoAtPathToSavedPhotosAlbum(movieURL, completionBlock: { (newURL, error) -> Void
you get the asset url in that newUrl completion block variable. Use it in the Facebook sharing call
let content = FBSDKShareVideoContent()
content.video = FBSDKShareVideo(videoURL: newURL)
FBSDKShareAPI.shareWithContent(content, delegate: self)
NSLog("Facebook content shared \(content.video.videoURL)")
You can do this sharing inside the completion block if you so desire, or you can save the newUrl from the completion block and use it somewhere else.

Resources