Posts

Post not yet marked as solved
0 Replies
320 Views
Hello, I am trying to integrate Firebase Analytics with my swift app and I have followed the instructions to do this integration on the official Firebase page and everything seems to work fine until I make use of the Analytics logEvent statement and it throws the following compile error: Undefined symbols for architecture x86_64: "_OBJCCLASS $ _ FIRApp", referenced from: objc-class-ref in AppDelegate.o "_OBJCCLASS $ _ FIRAnalytics", referenced from: objc-class-ref in FirebaseUtils.o
Posted
by Diego Cid.
Last updated
.
Post not yet marked as solved
1 Replies
1.3k Views
Hello, I am developing an app that allows access to different websites and shows the answer in a UIWebview. I have found that when trying to load a file from a web (html loaded in the UIWebview) using a file input, the app breaks in IOS13 and returns the following error:*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIDocumentMenuViewController (<UIDocumentMenuViewController: 0x7f7fbb021ea0>). In its current trait environment, the modalPresentationStyle of a UIDocumentMenuViewController with this style is UIModalPresentationPopover. You must provide location information for this popover through the view controller's popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the view controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.'I have been looking for solutions and I have found the solution that I show below to control the presentation of the UIDocumentMenuViewController should work, but it still gives the same error, since it does not enter the prepareForPopoverPresentation methodoverride open func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) { if #available(iOS 13, *), viewControllerToPresent is UIDocumentMenuViewController { viewControllerToPresent.popoverPresentationController?.delegate = self } super.present(viewControllerToPresent, animated: flag, completion: completion) } func prepareForPopoverPresentation(_ popoverPresentationController: UIPopoverPresentationController) { popoverPresentationController.sourceView = self.view }What am I doing wrong so it doesn't work?
Posted
by Diego Cid.
Last updated
.
Post marked as solved
16 Replies
8.3k Views
I am using the URLSession library to connect to certain pages using the https protocol. To get access to certain urls I had to create a delegate to include the public part of the certificate offered by the server. The problem I find is that in some urls the application does not call the method that I created in the delegate. What could be the problem? I include the snippet of the URLSession class and the delegated class that I created. let delegate: URLSessionDelegate = SessionDelegate() as URLSessionDelegate let urlSession = URLSession(configuration: .default, delegate: delegate, delegateQueue: nil) let task = urlSession.dataTask(with: request as URLRequest){ data, response, error in if error == nil { var htmlCode: String = "" if charset == Constantes.CHARSET_UTF8 { htmlCode = String(data: data!, encoding: .utf8)! } else { htmlCode = String(data: data!, encoding: .ascii)! } callback(htmlCode, nil) return } else { callback("", error.debugDescription) } } task.resume() And my delegate class: class SessionDelegate:NSObject, URLSessionDelegate { let certificadosName: [String] = ["AC_Administracion_Publica","ac_raiz_fnmt","Camerfirma_AAPP_II_Chambers_of_Commerce_Root","Camerfirma_Corporate_Server_II_Chambers_of_Commerce_Root","Chambers_of_Commerce_Root","claveRaiz","DigiCert_High_Assurance_EV_Root_CA","Entrust_Root_Certification_Authority_G","GeoTrust_SSL_CA_G_GeoTrust_Global_CA","Izenpe_com"] let certFileType = "cer" func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { guard challenge.previousFailureCount == 0 else { challenge.sender?.cancel(challenge) // Inform the user that the user name and password are incorrect completionHandler(.cancelAuthenticationChallenge, nil) return } if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust && challenge.protectionSpace.serverTrust != nil { let trust = challenge.protectionSpace.serverTrust var certs: [SecCertificate] = [SecCertificate]() for certificadoName in certificadosName { let pem = Bundle.main.url(forResource: certificadoName, withExtension: certFileType) let data = NSData(contentsOf: pem!) let cert = SecCertificateCreateWithData(nil, data!) certs.append(cert!) } SecTrustSetAnchorCertificates(trust!, certs as CFArray) var result=SecTrustResultType.invalid if SecTrustEvaluate(trust!,&result)==errSecSuccess { if result==SecTrustResultType.proceed || result==SecTrustResultType.unspecified { let proposedCredential = URLCredential(trust: trust!) completionHandler(.useCredential,proposedCredential) return } } } completionHandler(.performDefaultHandling, nil) } }
Posted
by Diego Cid.
Last updated
.
Post marked as solved
6 Replies
2.8k Views
I am trying to create a class that allows me to send POST requests to a website whose content type is application / x-www-form-urlencoded. The code I am using is as follows:import Foundation class HTTPClient { func getStringResponse(url: String, method: String, charset: String, parametros: [String: Any], headers: [String: Any])->String{ var htmlCode = "" connectionRequest(url: url, method: method, charset: charset, parametros: parametros, headers: headers, callback: { (data, error) in htmlCode = data }) while htmlCode == "" { } return htmlCode } func connectionRequest(url: String, method: String, charset: String, parametros: [String: Any], headers: [String: Any], callback: @escaping (String, String!) -> Void) { let myUrl = NSURL(string: url) let request = NSMutableURLRequest(url: myUrl! as URL) request.httpMethod = method if method == Constantes.METHOD_POST { var postString = "" for parametro in parametros { if postString.isEmpty { var cadena = parametro.key cadena.append("=") cadena.append(parametro.value as! String) postString.append(cadena) } else { var cadena = "&" cadena.append(parametro.key) cadena.append("=") cadena.append(parametro.value as! String) postString.append(cadena) } } var httpHeaders = [String: String]() httpHeaders["Cache-Control"] = "no-cache" httpHeaders["Content-Type"] = "application/x-www-form-urlencoded" for header in headers { httpHeaders[header.key] = header.value as! String } let encodeParameters: Data = postString.data(using: String.Encoding.utf8, allowLossyConversion: false)! let decodeParameters = String(data: encodeParameters, encoding: .utf8) request.allHTTPHeaderFields=httpHeaders request.httpBody = postString.data(using: String.Encoding.utf8, allowLossyConversion: false) } let task = URLSession.shared.dataTask(with: request as URLRequest) { data, response, error in if error == nil { let htmlCode = String(data: data!, encoding: .ascii) callback(htmlCode!, nil) return } } task.resume() }With this class if the parameter are simple, like "?name=One&surname=Two&city=City", this class works propertly. My problem is for large params. If I try to send next parameters it´s not working.I can´t add the value of parameters, so I add the link of this question I posted on stackoverflow that include the parma values: https://stackoverflow.com/questions/58474729/how-to-send-large-post-parameters-with-urlsessionIn my code, the variable decodeParameters have not the same value than postString after do the encode and decode process. Exists any limitation on the length of this type of parameters?
Posted
by Diego Cid.
Last updated
.