BrainTree DropIn credit card example - ios

I am trying to integrate BrainTree with ios using DropIn UI.
I succeeded to show the UI and when I use the test card
Number: 4111111111111111
Exp: 09/2020
It shows message
"Please review your information and try again"
let request = BTDropInRequest()
request.amount = "100"
request.paypalDisabled = true
request.shouldMaskSecurityCode = true
let dropIn = BTDropInController(authorization: tokenizationKey, request: request)
{ (controller, result, error) in
if (error != nil) {
print("ERROR = \(error?.localizedDescription ?? "")")
} else if (result?.isCancelled == true) {
print("CANCELLED")
} else if let result = result {
print("Payment Description = \(result.paymentDescription)")
print("paymentOptionType = \(result.paymentOptionType)")
print("paymentMethod = \(result.paymentMethod?.type ?? "")")
print("isCancelled = \(result.isCancelled)")
// Use the BTDropInResult properties to update your UI
// result.paymentOptionType = .
}
controller.dismiss(animated: true, completion: nil)
}
viewController.present(dropIn!, animated: true, completion: nil)
And here is the log when I click on Add Card
-canOpenURL: failed for URL: "com.venmo.touch.v2://x-callback-url/vzero/auth" - error: "This app is not allowed to query for scheme com.venmo.touch.v2"
TIC TCP Conn Failed [25:0x28008b3c0]: 12:8 Err(-65554)
Task .<2> HTTP load failed (error code: -1003 [12:8])
Task .<2> finished with error - code: -1003
TIC TCP Conn Failed [26:0x2800889c0]: 12:8 Err(-65554)
Task <650E9BB8-3AF6-4076-A6C4-977D0435B161>.<5> HTTP load failed (error code: -1003 [12:8])
Task <650E9BB8-3AF6-4076-A6C4-977D0435B161>.<5> finished with error - code: -1003
[BraintreeSDK] WARNING Failed to flush analytics events: A server with the specified hostname could not be found.

It seems that sandbox doesn't work on a real device when I switched to a simulator, request succeeded after adding a credit card details.
After changing to the production environment the same problem existed, After a several tries I changed from Wifi to LTE as connection in my iPhone device, and it worked! it seems that my ISP has no DNS for production Braintree backend

Related

Xcode HomeKit add device to Home app using X-HM: or code pin

I learn the Homekit to integrate my IOT device.
let payload = HMAccessorySetupPayload.init(url: URL.init(string: "X-HM://XXXXXXXXX"))
let request = HMAccessorySetupRequest()
request.payload = payload
let setupManager = HMAccessorySetupManager()
setupManager.performAccessorySetup(using: request) { (result, error) in
if (error != nil) {
print("Error from addAndSetupAccessories:", [error?.localizedDescription])
} else {
print("The accessory is added.")
}
}
The "X-HM" link is provided by OpenHab but it returned a error:
Failed to perform accessory setup using request: Error Domain=HMErrorDomain Code=17 "(null)"
I find other user say you need set the permission but I cannot set this in Entitlements file. It return error not find this.
“com.apple.developer.homekit.allow-setup-payload”
Question 1:
in the Homekit doc mean, the link must join "MFi Program"?
====
Question 2:
also, i have the pin code, Could i skip the input step in app setup?
i use the below code but this has not option to input the pin code, it need user to input using keyboard.
let setupManager = HMAccessorySetupManager()
setupManager.performAccessorySetup(using: HMAccessorySetupRequest()) { (result, error) in
if (error != nil) {
print("Error from addAndSetupAccessories:", [error?.localizedDescription])
} else {
print("The accessory is added.")
}
}

Request not firing when returning to app from background

I'm returning to my app which is in the background from a successful payment from another app. When returning, a patch request should be fired to change status from available to sold. The problem is that the request is never fired.
I use alamofire session manager to make the request. And the function making the request is used all over the project and it works. It is also not a server error or a threading error as it runs on the main thread and the server works through curl / swagger.
It seems to me that the app does not have internet connection or something of the sort when returning to the app. Loggs can be found down below. The request has been succesfully fired a couple of times, which makes be believe in the internet connection theory.
Here are some selected parts of the code.
lazy var manager: SessionManager = {
let sessionManager = Alamofire.SessionManager.default
sessionManager.session.configuration.timeoutIntervalForRequest = 40
sessionManager.adapter = OauthHandler.sharedInstance
sessionManager.retrier = OauthHandler.sharedInstance
return sessionManager
}()
func authenticateRequestWithRouter(_ router: BaseRouter, shouldShowErrorAlert: Bool = true, _ completion: requestResponse?) {
let request = router.asURLRequest()
manager.request(request).validate().responseJSON() { [weak self] response in
switch response.result {
case .success(let data):
completion?(true, data, nil)
case .failure(let error):
if shouldShowErrorAlert,
let errorMessage = self?.parseErrorMessage(fromData: response.data, request: request) {
self?.showErrorAlert(message: errorMessage)
}
completion?(false, response.data, error)
}
}
}
Logs that have been occuring:
Returning ENOTCONN because protocol has not yet been set up
nw_connection_copy_connected_local_endpoint [C7] Connection has no
local endpoint
HTTP load failed (error code: -1005 [1:57])
Domain=NSURLErrorDomain Code=-1005 "The network connection was lost."
Domain=NSPOSIXErrorDomain Code=53 "Software caused connection abort"
nw_protocol_boringssl_error(1584) [C1.1:2][0x102838b30] Lower protocol
stack error: 53

How to set AWS Appsync request timeout limit || AWSAppSync Client not giving callback

I'm using AWS Appsync for the current App I'm developing and facing a serious issue that is Whenever I fire queries in Appsync client, when there is slow internet connection the request never end with a callback. I checked over internet there is limited source of information on this topic and also found this issue that is still open.
This is the code I used to get the response
func getAllApi(completion:#escaping DataCallback){
guard isInternetAvailabele() else {
completion(nil)
return
}
// AppSyncManager.Client() is AWSAppSyncClient Object
AppSyncManager.Client().fetch(query: GetlAllPostQuery(input: allInputs), cachePolicy:.fetchIgnoringCacheData) {
(result, error) in
var haveError:Bool = error != nil
if let _ = result?.data?.getAllPostings?.responseCode {haveError = false} else {haveError = true}
if haveError {
print(error?.localizedDescription ?? "")
completion(nil)
return
}
if result != nil{
completion(result)
}else{
completion(nil)
}
}
}
The code works fine with internet connection and I have already checked at the top if there is no internet but when there is slow internet connection or the wifi is connected to a hotspot that I created with my mobile with internet data disabled the request doesn't return any callback it should give failed alert like we get in other apis when the request time out.
Is there any support for request for request time out or did I miss something?
Note : I recieved these logs in Terminal
Task <06E9BBF4-5731-471B-9B7D-19E5E504E57F>.<45> HTTP load failed (error code: -1001 [1:60])
Task <D91CA952-DBB5-4DBD-9A90-98E2069DBE2D>.<46> HTTP load failed (error code: -1001 [1:60])
Task <06E9BBF4-5731-471B-9B7D-19E5E504E57F>.<45> finished with error - code: -1001
Task <D91CA952-DBB5-4DBD-9A90-98E2069DBE2D>.<46> finished with error - code: -1001
Actually there could be two possible ways to fix the issue,
1) While configuring AWSAppSyncClientConfiguration, provide a custom URLSessionConfiguration and set the request timeout to your needs,
extension URLSessionConfiguration {
/// A `URLSessionConfiguration` to have a request timeout of 1 minutes.
static let customDelayed: URLSessionConfiguration = {
let secondsInOneMinute = 60
let numberOfMinutesForTimeout = 1
let timoutInterval = TimeInterval(numberOfMinutesForTimeout * secondsInOneMinute)
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = timoutInterval
configuration.timeoutIntervalForResource = timoutInterval
return configuration
}()
}
And pass this session configuration i.e URLSessionConfiguration.customDelayed when initializing AWSAppSyncClientConfiguration as it accepts the URLSessionConfiguration in the below constructor,
public convenience init(url: URL,
serviceRegion: AWSRegionType,
credentialsProvider: AWSCredentialsProvider,
urlSessionConfiguration: URLSessionConfiguration = URLSessionConfiguration.default,
databaseURL: URL? = nil,
connectionStateChangeHandler: ConnectionStateChangeHandler? = nil,
s3ObjectManager: AWSS3ObjectManager? = nil,
presignedURLClient: AWSS3ObjectPresignedURLGenerator? = nil) throws {
2) If the first doesn't work then you have another option to edit/unlock the pod files directly. There is a class AWSAppSyncRetryHandler where you can change the logic for retrying request. If you are able to fix the issue then you can fork the original repo, clone your repo, make changes in your repo and in pods file point this pod to use your repository. This should be done as changing the pod files directly is absolutely wrong until you are really stuck and want to find some solution.
Update: This issue has been fixed with AppSync SDK 2.7.0

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)

iOS App crashes when the service is closed

I've been writing an app with Swift 4 and it communicates with a service via RESTful API.
I have found some helpful code examples and everything works well as the service is running.
However, I could not handle the situation that the service is closed. I have tried try/catch blocks but they did not work well. Please check the code below firstly. It's the part of the communication. Basically it sends an email address to the service and gets a response as an activation code.
URLSession.shared.dataTask(with: request) { (data:Data?, response:URLResponse?, error:Error?) in
guard error == nil else {
// Some code
return
}
guard let responseData = data else {
// Some code
return
}
do {
guard let activation_response = try JSONSerialization.jsonObject(with: responseData, options: [])
as? [String: Any] else {
// Some code
return
}
guard let activation_code = activation_response["activation_code"] as? String else {
// Some code
return
}
// Some code, here, if it works fine.
} catch {
// Some code
return
}
}.resume()
When the service is closed, simply it will throw an error such as TCP connection failed. How can I handle it?
The error I get is something like below:
TheApp[4184:399699] TIC TCP Conn Failed [1:0x604000166600]: 1:61 Err(61)
2018-01-02 20:35:04.930874+0300 TheApp[4184:399699] Task <5ED49B16-BFDC-45A5-85F5-095C4FC4D84D>.<1> HTTP load failed (error code: -1004 [1:61])
2018-01-02 20:35:04.934352+0300 TheApp[4184:399698] Task <5ED49B16-BFDC-45A5-85F5-095C4FC4D84D>.<1> finished with error - code: -1004
It throws an exception and I can not catch it. I could not find how to do it. Thank you very much in advance for your help.

Resources