ios


Image URL to UIImage Not Working


let url = URL(string: (pinsFIREBASE[marker.snippet!]?.imageURL)!)
let task = URLSession.shared.dataTask(with: url!) { data, response, error in
guard let data = data, error == nil else { return }
DispatchQueue.main.async() {
self.postImage.image = UIImage(data: data)
}
}
task.resume()
I have the following code that takes a url from firebase, in the form http://i.imgur.com/nkomPpP.jpg, and is supposed to turn that url into a UIImage that can be placed on a view. However, while extracting the text from the firebase object works, parsing the image URL doesn't seem to be working as I get an empty view. What am I doing wrong?
I know why, your code works. The problem is your image link. Your imageURL's HTTP type. iOS don't like HTTP type request because it's not safe.
Plan A: Try a HTTPS type image link, it works.
Plan B: Add "App Transport Security Settings" in project info ,and set "Allow
Arbitrary Loads" yes in "App Transport Security Settings" dictionary.
I suggested use Plan A, that's Apple want iOSDev to do.
You need to remove the () from after DispatchQueue.main.async(). Try this:
let url = URL(string: (pinsFIREBASE[marker.snippet!]?.imageURL)!)
let task = URLSession.shared.dataTask(with: url!) { data, response, error in
guard let data = data, error == nil else { return }
DispatchQueue.main.async {
self.postImage.image = UIImage(data: data)
}
}
task.resume()

Related Links

Programmatically Create Popover Menu Swift
How can I pass body parameters along with file in multipart file upload using Alamofire in Swift
Xcode 7 UI Testing with Cocoapods fails on device
Error using performSegueWithIdentifier Swift 2.1
Twitter does not return email id after whitelisting in iOS
Delphi 10 Seattle missing libsqlib.a
How to convert date like \/Date(1440156888750-0700)\/ to something that Swift can handle?
Calling Class level code inside block crashes objective c
How to add number of rows in section dynamically in tableview? [closed]
iOS Network Connection Failure Policy suggestions
TTTAttributedLabel link font changing when UIAlertView presents
tell an array to hold instances of an array?
Add Vibrancy effect to custom UIButton?
Image buffer display order with VTDecompressionSession
What is that? Cell or Table? [closed]
Setting up proxy server on iPhone

Categories

HOME
sbt
asp.net-mvc
graph
oozie
jsp
xaml
robotframework
android-wear
fonts
swashbuckle
prometheus
mvvm-light
sony
gcov
doorkeeper
signature
graph-tool
googletest
records
oracle11gr2
abaqus
lexikjwtauthbundle
hp-alm
game-maker-language
dotnetbar
man
ormlite-servicestack
microphone
zos
burp
liferay-aui
sumifs
laravel-valet
whatsapi
kubernetes-go-client
pyparsing
scom
apex-code
groove
webcenter
powerbuilder-conversion
bits
joe-editor
jsonstore
firedac
subscription
win2d
distributed-lock
virtualmin
default-browser
smartbanner
domdocument
formstack
database-cleaner
sshd
dwr
jahia
assembly-references
findall
dr-memory
perspective
measurement-protocol
webtrends
file-import
ellipsis
pygments
finalcut
visual-build-professional
formatter
python-3.1
lidar
filenet-content-engine
parsoid
clientid
nominatim
spymemcached
rdotnet
xerces
boxapiv2
iqueryable
linguistics
xacml3
fig
sirtrevor
confirmation
nawk
blueprint
location-client
webcal
icon-fonts
layout-manager
locomotivejs
asp.net-session
harvest
google-profiles-api
hpple
magento-1.5
ember-router
openid4java
emacs-ecb
indextank
cassandra-0.7
clipboard-pictures
crc-cards
nhaml
roguelike

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App