TIC SSL Trust Error while accessing data from https url - ios

I have tried to access data from a https url by following.
DispatchQueue.global(qos: .background).async {
let stringURL = "https://192.168.104.91:8443/update_info.xml"
let url = URL(string: stringURL)
var data:Data? = nil
do {
data = try Data(contentsOf: url!)
} catch {
print(error.localizedDescription)
}
}
But i am getting following error.
2018-03-21 12:49:35.529949+0600 AppName[704:205346] TIC SSL Trust Error [1:0x1c0171a00]: 3:0
2018-03-21 12:49:35.541223+0600 AppName[704:205346] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
2018-03-21 12:49:35.541283+0600 AppName[704:205346] Task <7D4A1063-B946-4588-830A-CE73AF5B4995>.<0> HTTP load failed (error code: -1202 [3:-9813])
2018-03-21 12:49:35.541771+0600 AppName[704:205344] NSURLConnection finished with error - code -1202
The file “update_info.xml” couldn’t be opened.
Any suggestions ?

Related

Why I can't access my nodejs local server from iOs simulator

I am trying to make an http request from my xcode to my local server running on nodejs. The following in a part of my iOs code.
let url = URL(string: "http://localhost.com/signup")!
let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
guard let data = data else { return }
print(String(data: data, encoding: .utf8)!)
}
task.resume()
I recieve the following the response
Error Domain=NSURLErrorDomain Code=-1001 "The request timed out."
Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be
found.
I receive the first error if I use localhost.com and I receive the second error if I change the request to www.localhost.com
in this case you have to use your IP to get access to your localhost
ex: let url = URL(string: "http://192.168.1.105/signup")!
so Instead of using (localhost.com/...) you have to set the IP of your computer where you have LOCAL SERVER.

Not able to upload Images on to Google Firebase Storage using iOS Swift API

Earlier i was able to upload Images onto Google Firebase Strage. but suddenly it's not working.
Below is the code:
private func uploadEmergencyImages(images: [Int: URL], emergencyId: String){
let imagesRef = Storage.storage().reference().child("incidents").child(emergencyId).child("images")
if(!images.isEmpty){
for (key, value) in images {
print("Image to be Uploaded = \(value.absoluteString)")
let imageData = try! Data(contentsOf: value)
// let image = UIImage(data: imageData)
let metaData = StorageMetadata()
metaData.contentType = "image/png"
imagesRef.child("Image_\(key+1).png").putData(imageData, metadata: metaData) { (storageMetaData, storageError) in
if(storageError != nil){
print("Error - While uploading Image:: \(storageError.debugDescription)")
}else{
print("Upload completed...")
}
}
}
}
}
Below is the Error message (NOTE: Here i have masked my firebasePrjName with 'XXX' for this post.)
2018-08-23 20:25:54.758092+0300 XXX[44855:1058133] [AXRun-PID] Client
requesting unsuspension of PID:44870 Name: 2018-08-23
20:25:55.833590+0300 XXX[44855:1057851] [AXRun-PID] Client requesting
unsuspension of PID:44870 Name: 2018-08-23
20:25:57.512286+0300 XXX[44855:1057987] [discovery] errors encountered
while discovering extensions: Error Domain=PlugInKit Code=13 "query
cancelled" UserInfo={NSLocalizedDescription=query cancelled} New
Incident Key = -LKboaL9nTohkCHuYp1U Image to be Uploaded =
file:///Users/macbookpro/Library/Developer/CoreSimulator/Devices/863EEA6A-F1F5-4A6C-B19B-D686D81486F4/data/Containers/Data/Application/F0D6F426-EE5E-4B45-8D1F-3B880C049DF3/tmp/39F05E90-3F8F-4A40-84CB-1931D1E9C7CA.jpeg
2018-08-23 20:26:07.359567+0300 XXX[44855:1058132] TIC TCP Conn Failed
[4:0x60400036ffc0]: 3:-9802 Err(-9802) 2018-08-23 20:26:07.360138+0300
XXX[44855:1058132] NSURLSession/NSURLConnection HTTP load failed
(kCFStreamErrorDomainSSL, -9802) 2018-08-23 20:26:07.360235+0300
XXX[44855:1058132] Task .<1>
HTTP load failed (error code: -1200 [3:-9802]) 2018-08-23
20:26:07.360437+0300 XXX[44855:1057735] Task
.<1> finished with error - code:
-1200 Error - While uploading Image:: Optional(Error Domain=FIRStorageErrorDomain Code=-13000 "An unknown error occurred,
please check the server response."
UserInfo={NSLocalizedRecoverySuggestion=Would you like to connect to
the server anyway?, NSLocalizedDescription=An unknown error occurred,
please check the server response., _kCFStreamErrorDomainKey=3,
NSErrorPeerCertificateChainKey=(
"",
"" ), NSErrorClientCertificateStateKey=0,
NSErrorFailingURLKey=https://firebasestorage.googleapis.com/v0/b/XXX-ots.appspot.com/o/incidents%2F-LKboaL9nTohkCHuYp1U%2Fimages%2FImage_1.png?uploadType=resumable&name=incidents%2F-LKboaL9nTohkCHuYp1U%2Fimages%2FImage_1.png,
NSErrorFailingURLStringKey=https://firebasestorage.googleapis.com/v0/b/XXX-ots.appspot.com/o/incidents%2F-LKboaL9nTohkCHuYp1U%2Fimages%2FImage_1.png?uploadType=resumable&name=incidents%2F-LKboaL9nTohkCHuYp1U%2Fimages%2FImage_1.png,
NSUnderlyingError=0x600000647290 {Error Domain=kCFErrorDomainCFNetwork
Code=-1200 "(null)"
UserInfo={_kCFStreamPropertySSLClientCertificateState=0,
kCFStreamPropertySSLPeerTrust=,
_kCFNetworkCFStreamSSLErrorOriginalValue=-9802, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9802, kCFStreamPropertySSLPeerCertificates=(
"",
"" )}}, _kCFStreamErrorCodeKey=-9802,
object=incidents/-LKboaL9nTohkCHuYp1U/images/Image_1.png,
ResponseErrorDomain=NSURLErrorDomain, bucket=XXX-ots.appspot.com,
NSURLErrorFailingURLPeerTrustErrorKey=,
ResponseErrorCode=-1200})
I had tried to modify my info.plist file as below also, but it did not work:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Any lead is highly appreciated.
This is working for me (swift 4 Code)
let storageRef = DBProvider.Instance.imageStorageRef.child(user!.uid) // Put Here your Storage Referance
let imageData = UIImageJPEGRepresentation(youimagehere, 1.0) // put your image Here
storageRef.putData(imageData!, metadata: nil, completion: { (metadata, error) in
if error == nil
{
let path = metadata?.downloadURL()?.absoluteString
print(path)
}
})
Make sure you have enabled firebase storage read, write Permission from your Firebase project.

Firebase Task finished with error - code: -1200

I am unable to access data from Firebase storage on my iOS app on my current connection. When I connect to a VPN, it allows me to connect and download data from Firebase Storage normally. I have also tried to allow arbitrary loads but to no use. Any suggestions?
The following is the code:
let tempImageRef = storage.child("CoverArt/Issue15.jpg")
tempImageRef.getData(maxSize: 1*1000*1000) { (data, error) in
if (error == nil)
{ //Do something }
else { print(error!.localizedDescription) } }
The following is the error:
Task <D343DC6F-2D37-4246-A0BA-4044BF36C83D>.<1> finished with error - code: -1200 An unknown error occurred, please check the server response.
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)

Error Loading objects from a Web Server

I use this code to get my objects on web like the Ikea app, but it's not working and gives me the error below.
func loadModel() {
let virtualObjectURL: URL!
virtualObjectURL = URL(string: "https://example.com/\(modelName).\(fileExtension)")
let virtualObjectScene = try! SCNScene(url: virtualObjectURL)
let wrapperNode = SCNNode()
for child in virtualObjectScene.rootNode.childNodes {
child.geometry?.firstMaterial?.lightingModel = .physicallyBased
child.movabilityHint = .movable
wrapperNode.addChildNode(child)
}
self.addChildNode(wrapperNode)
modelLoaded = true
}
It looks like an SSL certificate error, but I tried AllowArbitaryLoads and it didn't work.
Must I use MySQL or something? I feel like if I don't have any SSL certificate errors, it gives me another error.
2017-11-15 18:18:05.669124+0300 ARKitProject[2908:2157180] Strict Trust Evaluation yielded status(-9802) for [1:0x1c416f780]
2017-11-15 18:18:05.669206+0300 ARKitProject[2908:2157180] TIC SSL Trust Error [1:0x1c416f780]: 3:0
2017-11-15 18:18:05.669430+0300 ARKitProject[2908:2157180] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
2017-11-15 18:18:05.669469+0300 ARKitProject[2908:2157180] Task <DF717E27-6EC4-4800-8B1A-01D6B796CFE7>.<0> HTTP load failed (error code: -1200 [3:-9802])
2017-11-15 18:18:05.670112+0300 ARKitProject[2908:2157268] NSURLConnection finished with error - code -1200

How can I get source code from URL with SSL using Swift?

I am trying to read a source code of a site from its URL.
Below is my code.
let myURLString = "https://theUrlOfTheSite"
let myURL = NSURL(string: myURLString)
var error: NSError?
let myHTMLString = String(contentsOfURL: myURL!, encoding: NSUTF8StringEncoding, error: &error)
if let error = error {
println("Error : \(error)")
} else {
println(myHTMLString)
}
It works for some site, but not for others. I get the following error
2014-12-21 19:11:54.032 MyPlayground[2912:345862] NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9807)
Error : Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)"
I think it's because the site is https, not http. (I don't really know about this stuff but..SSL something??)
So my question is, what should I do to make my code work??
I searched for hours but I'm new to iOS and Swift, so no progress.
Do I have to make NSURLConnection or something? Because all I want to do is get the source code. Must be a simple job I guess..
Any help will be appreciated. Thanks in advance.

Resources