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

Message sent to deallocated instance in swift
How can I read a json file in the Documents Directory in swift?
NSFastEnumerationIterator.Element (aka Any) has no subscript members
What is the difference between the modal presentation style “over current context” and “over fullscreen”?
(iOS) Increasing memory consumption related to GameScene
UICollectionView crashes when scrolling to the bottom
Flexbox on IOS scrolls differently
Firing an embeded AVPlayerViewController programatically from a TableView
Dissmiss alertview created by LMAlertView on outside tap
Cordova build failed for ios after installing pushwoosh notifications plugin
Facebook not redirecting to application from safari view
Custom rounded UIView in Swift?
Swift concatenate string based on different values
Xcode 8 GM App running on simulator but not on device pods issue
WKWebView loadFileURL works only once
solve error - ambiguous reference to member 'collectionView(_numberOfItemsInSection:)'

Categories

HOME
asp.net-mvc
wpf
azure-search
appium-ios
bolt-cms
backand
windows-runtime
antlr
httpbuilder-ng
splunk
drag
intl
gcov
google-cloud-sdk
next
web-audio
flow
aerospike
pydev
selenium-edgedriver
android-arrayadapter
true-type-fonts
feedly
html-select
background-process
stackexchange.exceptional
advanced-installer
presto
macvim
confirm
amazon-elasticsearch
sagepay
easy-digital-downloads
integer-programming
oracle-aq
zuul
g-wan
javascript-security
cmsmadesimple
qtcpserver
singlepage
postmark
android-sdk-tools
mysql-notifier
rails-console
perspective
measurement-protocol
printscreen
webdeploy-3.5
groups
armv7
ssha
jedi
session-replication
wt
xsb
node-orm2
sketching
mks
words
physx
httpservice
clearcase-remote-client
directcompute
data-quality
magento-1.6
yourls
windows-phone-7.1
android-lru-cache
resolver
buildout
micro-orm
zephir
webcal
git-gui
asp.net-authentication
alternate-data-stream
timespan
guvnor
51degrees
msxsl
zmodem
bubble-popup
xmltextwriter
remote-control
ryz
xtratreelist
msn-messenger
nhaml
docking

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