FCM push notification via AlamoFire - URLSessionTask failed with error: Could not connect to the server - ios

I'm trying to implement FCM to send a push notification (using the legacy api), but am unable to do so.
I have verified that my server key (taken from Firebase console) and device token are accurate, and I have successfully sent a push note to my device via Postman.
However, I am unable to do so via code. I am calling the below code from my simulator and "attempting" to send a push note to my physical device.
let urlString: String = "https://fcm/googleapis.com/fcm/send"
let key = "key=[my server key]"
let headers: HTTPHeaders = [
"Content-Type": "application/json",
"Authorization": key
]
let notificationParameters: Parameters = [
"to": "[my push token of physical device]",
"notification": [
"title": "My title",
"body": "My body"
]
]
print("1")
AF.request(urlString, method: .post, parameters:
notificationParameters, encoding: JSONEncoding.default, headers:
headers).responseJSON { response in
print("3")
switch response.result {
case .success:
printSuccess("Successfully sent notification")
case .failure(let error):
print("Failed to send notification: \(error)")
print(error.errorDescription)
print(error.failureReason)
}
print("4")
}
print("2")
Here's the log:
1
2
2022-03-31 15:23:24.725607-0500 Wurtle with Friends[22207:12775410]
[connection] nw_socket_handle_socket_event [C3.1:3] Socket SO_ERROR
[61: Connection refused]
2022-03-31 15:23:24.727572-0500 Wurtle with Friends[22207:12775410]
Connection 3: received failure notification
2022-03-31 15:23:24.727789-0500 Wurtle with Friends[22207:12775410]
Connection 3: failed to connect 1:61, reason -1
2022-03-31 15:23:24.728130-0500 Wurtle with Friends[22207:12775410]
Connection 3: encountered error(1:61)
2022-03-31 15:23:24.729779-0500 Wurtle with Friends[22207:12775409]
[boringssl] boringssl_metrics_log_metric_block_invoke(153) Failed
to log metrics
2022-03-31 15:23:24.731134-0500 Wurtle with Friends[22207:12775410]
Task <B52206D8-E22D-4D8F-B3F5-815692558860>.<1> HTTP load failed,
0/0 bytes (error code: -1004 [1:61])
2022-03-31 15:23:24.736922-0500 Wurtle with Friends[22207:12775410]
Task <B52206D8-E22D-4D8F-B3F5-815692558860>.<1> finished with error
[-1004] Error Domain=NSURLErrorDomain Code=-1004 "Could not connect
to the server." UserInfo={_kCFStreamErrorCodeKey=61,
NSUnderlyingError=0x60000279c300 {Error
Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo=
{_NSURLErrorNWPathKey=satisfied (Path is satisfied), interface:
en1, _kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}},
_NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <B52206D8-
E22D-4D8F-B3F5-815692558860>.<1>,
_NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <B52206D8-E22D-4D8F-B3F5-815692558860>.<1>"
), NSLocalizedDescription=Could not connect to the server.,
NSErrorFailingURLStringKey=https://fcm/googleapis.com/fcm/send,
NSErrorFailingURLKey=https://fcm/googleapis.com/fcm/send,
_kCFStreamErrorDomainKey=1}
3
Failed to send notification: sessionTaskFailed(error: Error
Domain=NSURLErrorDomain Code=-1004 "Could not connect to the
server." UserInfo={_kCFStreamErrorCodeKey=61,
NSUnderlyingError=0x60000279c300 {Error
Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo=
{_NSURLErrorNWPathKey=satisfied (Path is satisfied), interface:
en1, _kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}},
_NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <B52206D8-
E22D-4D8F-B3F5-815692558860>.<1>,
_NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <B52206D8-E22D-4D8F-B3F5-815692558860>.<1>"
), NSLocalizedDescription=Could not connect to the server.,
NSErrorFailingURLStringKey=https://fcm/googleapis.com/fcm/send,
NSErrorFailingURLKey=https://fcm/googleapis.com/fcm/send,
_kCFStreamErrorDomainKey=1})
Optional("URLSessionTask failed with error: Could not connect to
the server.")
4
This is my first time implementing FCM and I've been stuck on it for a while now, so any help is appreciated. Thank you

Even though I do not recommend sending an FCM request straight from the app, it appears you have a typo in your server URL address.
Just change it to https://fcm.googleapis.com/fcm/send

you must get the FCM token and refresh token as the firebase console said in the Appdelegate file:
https://firebase.google.com/docs/cloud-messaging/ios/client
you shouldn't send push from the iOS app, this is not secure because of the server key and etc, and also you must add the cloud message certificate and message key as firebase requested.
and also you must have destination fcm token (per device).
Push Notification Sender must be your Backend that have all device FCM Tokens.
you must send FCM Token that you get in Appdelegate per ["user" , "device"] to backend and your backend must save it for user device.
FCM Token is a map key foreach device APNS token.

Related

Making network request from iOS App Extension returns error: "A server with the specified hostname could not be found"

I'm trying to download a language translation model from Google MLKit. I can download the model successfully on the main iOS app, but when I try to download it on the keyboard extension app, I receive an error: "A server with the specified hostname could not be found."
testKeyboard[43687:3987699] [] networkd_settings_read_from_file Sandbox is preventing this process from reading networkd settings file at "/Library/Preferences/com.apple.networkd.plist", please add an exception.
testKeyboard[43542:3979636] [discovery] [d 6BF0C0BD-3B78-43CD-A23F-26023D59A4F3] <PKHost:0x283acc400> Failed discovery: Error Domain=PlugInKit Code=4 "Connection invalid" UserInfo={NSLocalizedDescription=Connection invalid}.
testKeyboard[43542:3979636] [xpc] XPC error sending request to pkd: Connection invalid
testKeyboard[43542:3979662] [] nw_resolver_can_use_dns_xpc_block_invoke Sandbox does not allow access to com.apple.dnssd.service
testKeyboard[43542:3979662] dnssd_clientstub ConnectToServer: connect() failed path:/var/run/mDNSResponder Socket:9 Err:-1 Errno:1 Operation not permitted
testKeyboard[43542:3979662] [connection] nw_resolver_create_dns_service_locked [C1] DNSServiceCreateDelegateConnection failed: ServiceNotRunning(-65563)
testKeyboard[43542:3979662] Task <38FA4936-22C4-4E80-BECC-1D592945BE52>.<1> HTTP load failed, 0/0 bytes (error code: -1003 [10:-72000])
testKeyboard[43542:3979662] Task <38FA4936-22C4-4E80-BECC-1D592945BE52>.<1> finished with error [-1003] Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo={_kCFStreamErrorCodeKey=-72000, NSUnderlyingError=0x2821c14a0 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)" UserInfo={_kCFStreamErrorCodeKey=-72000, _kCFStreamErrorDomainKey=10}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDownloadTask <38FA4936-22C4-4E80-BECC-1D592945BE52>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDownloadTask <38FA4936-22C4-4E80-BECC-1D592945BE52>.<1>"
), NSLocalizedDescription=A server with the specified hostname could not be found., NSErrorFailingURLStringKey=https://redirector.gvt1.com/edgedl/translate/offline/v5/high/r24/en_es.zip, NSErrorFailingURLKey=https://redirector.gvt1.com/edgedl/translate/offline/v5/high/r24/en_es.zip, _kCFStreamErrorDomainKey=10}
error downloading Optional(Error Domain=com.google.mlkit Code=2 "Failed to download the model from the server." UserInfo={NSLocalizedDescription=Failed to download the model from the server.})
I'm using the same code to download the model according to Google's "Translate Text with MLKit on iOS" documentation in the KeyboardViewController's viewDidLoad() function:
let options = TranslatorOptions(sourceLanguage: .english, targetLanguage: .spanish)
self.translator = Translator.translator(options: options)
let conditions = ModelDownloadConditions(allowsCellularAccess: true, allowsBackgroundDownloading: true )
self.translator!.downloadModelIfNeeded(with: conditions) { error in
guard error == nil else {
print("error downloading", error)
return
}
print("Model downloaded successfully")
}
My Info.plist settings are such:
"RequestsOpenAccess" as 1
"App Transport Security Settings" > "Allow Arbitrary Loads" as YES
I don't understand what is going on here. Why am I able to download the ML Kit language model on the main app, but not on the keyboard extension? Any help appreciated.
The issue is with your project's Sandbox settings. Go to your project page / Signing & Capabilities / App Sandbox (Xcode 13.2) and then enable Outgoing Connections (Client) which will allow your app to make http calls.

How to silence debug logging with Alamofire (or NSUrlSession)?

Xcode 12.2,
Alamofire 5.4.0,
Swift 5
I have this snippet of code to request data from a backend which works fine in the happy flow.
But if for some reason the backend is unreachable, I see autogenerated logging I want it to hide or silence. Because it's disturbing me when I'm analysing debug logging.
let request = AF.request("http://192.168.1.5:44444/api/users", headers: headers)
request.responseJSON { (data) in
switch data.result {
case .success:
print("Request Succes!")
case .failure(let errorData):
print("Request Failed")
print("\(errorData.errorDescription ?? "")")
}
}
Error output:
Task <xxxxxxxx>.<1> HTTP load failed, 0/0 bytes (error code: -1004 [1:61])
Task <xxxxxxxx>.<1> finished with error [-1004] Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo={_kCFStreamErrorCodeKey=61, NSUnderlyingError=0x600000d82250 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <xxxxxxxxx>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <xxxxxxxxx>.<1>"
), NSLocalizedDescription=Could not connect to the server., NSErrorFailingURLStringKey=http://192.168.1.5:44444/developer, NSErrorFailingURLKey=http://192.168.1.5:44444/developer, _kCFStreamErrorDomainKey=1}
Request Failed
URLSessionTask failed with error: Could not connect to the server.
I want to get rid of the following, which is not generated by me:
Task <xxxxxxxx>.<1> HTTP load failed, 0/0 bytes (error code: -1004 [1:61])
Task <xxxxxxxx>.<1> finished with error [-1004] Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo={_kCFStreamErrorCodeKey=61, NSUnderlyingError=0x600000d82250 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <xxxxxxxxx>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <xxxxxxxxx>.<1>"
), NSLocalizedDescription=Could not connect to the server., NSErrorFailingURLStringKey=http://192.168.1.5:44444/developer, NSErrorFailingURLKey=http://192.168.1.5:44444/developer, _kCFStreamErrorDomainKey=1}
and see only:
Request Failed
URLSessionTask failed with error: Could not connect to the server.
These are system logs produced by the OS, not Alamofire. While you can silence them by disabling the os subsystem, I don't recommend it, as that disables all os_logs in your app and other os module functionality, like signposts. A feature request to Apple using Feedback Assistant may eventually convince them to let us filter these in Xcode.
I had exactly the same issue, I want to only the the debug entries created by me and not the ones by the system. I solved this using a prefix for all my own log entries. For example "[sync] Synchronizing from server..." or "[sync] Couldn't connect to server.".
Now you can set the filter in XCode (at the bottom of the log pane) to the prefix "[sync]" and you only see your own entries. This even works while running the app and the logs come in!

Fail to connect with Firebase [IOS/Swift]

I encountered a weird problem trying to connect with firebase in my project. I already followed all necessary steps - firebase config, cocopod, google.plist - but I keep getting these error messages in this screenshot. Does anyone else encounter this problem and how did you resolve it?
Sceenshot
AppDelegate
import UIKit
import Firebase
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
return true
}
Console
2020-10-25 10:47:24.604330-0400 test2[2991:35955] Connection 1: received failure notification
2020-10-25 10:47:24.604477-0400 test2[2991:35955] Connection 1: failed to connect 1:61, reason -1
2020-10-25 10:47:24.604584-0400 test2[2991:35955] Connection 1: encountered error(1:61)
2020-10-25 10:47:24.609628-0400 test2[2991:35955] Task <EF95DB6A-2445-4E58-9B2F-AFA35EE0A68E>.<1> HTTP load failed, 0/0 bytes (error code: -1004 [1:61])
2020-10-25 10:47:24.616313-0400 test2[2991:35955] Task <EF95DB6A-2445-4E58-9B2F-AFA35EE0A68E>.<1> finished with error [-1004] Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo={NSUnderlyingError=0x600001748c90 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}, NSErrorFailingURLStringKey=https://firebaselogging-pa.googleapis.com/v1/firelog/legacy/batchlog, NSErrorFailingURLKey=https://firebaselogging-pa.googleapis.com/v1/firelog/legacy/batchlog, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=61, NSLocalizedDescription=Could not connect to the server.}
2020-10-25 10:47:24.645716-0400 test2[2991:35949] 6.34.0 - [Firebase/Analytics][I-ACS023007] Analytics v.60900000 started
2020-10-25 10:47:24.649697-0400 test2[2991:35949] 6.34.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/)
2020-10-25 10:47:24.651125-0400 test2[2991:35955] 6.34.0 - [Firebase/Analytics][I-ACS023171] Resetting App Measurement data
2020-10-25 10:47:24.752809-0400 test2[2991:35975] 6.34.0 - [Firebase/Analytics][I-ACS800023] No pending snapshot to activate. SDK name: app_measurement
2020-10-25 10:47:24.788481-0400 test2[2991:35949] 6.34.0 - [Firebase/Analytics][I-ACS023012] Analytics collection enabled
2020-10-25 10:47:24.789629-0400 test2[2991:35949] 6.34.0 - [Firebase/Analytics][I-ACS023220] Analytics screen reporting is enabled. Call +[FIRAnalytics logEventWithName:FIREventScreenView parameters:] to log a screen view event. To disable automatic screen reporting, set the flag FirebaseAutomaticScreenReportingEnabled to NO (boolean) in the Info.plist
2020-10-25 10:47:39.183384-0400 test2[2991:36053] [] nw_socket_handle_socket_event [C3.1:3] Socket SO_ERROR [61: Connection refused]
2020-10-25 10:47:39.183765-0400 test2[2991:36053] [BoringSSL] nw_protocol_boringssl_handshake_negotiate_proceed(726) [0x7fd4bee004a0] handshake failed at state 0
2020-10-25 10:47:39.185931-0400 test2[2991:36053] Connection 3: received failure notification
2020-10-25 10:47:39.186090-0400 test2[2991:36053] Connection 3: failed to connect 1:61, reason -1
2020-10-25 10:47:39.186224-0400 test2[2991:36053] Connection 3: encountered error(1:61)
2020-10-25 10:47:39.190919-0400 test2[2991:36053] Task <69F833DC-E03D-46E7-A72D-DE7246C8BDFF>.<1> HTTP load failed, 0/0 bytes (error code: -1004 [1:61])
2020-10-25 10:47:39.192171-0400 test2[2991:35790] Task <69F833DC-E03D-46E7-A72D-DE7246C8BDFF>.<1> finished with error [-1004] Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo={_kCFStreamErrorCodeKey=61, NSUnderlyingError=0x600001732970 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDownloadTask <69F833DC-E03D-46E7-A72D-DE7246C8BDFF>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=("LocalDownloadTask <69F833DC-E03D-46E7-A72D-DE7246C8BDFF>.<1>"), NSLocalizedDescription=Could not connect to the server., NSErrorFailingURLStringKey=https://app-measurement.com/config/app/1:955410733527:ios:c82bc7afb517ae10479392?platform=ios&app_instance_id=3A4D3A72AC624838AB769B6871063F58&gmp_version=60900, NSErrorFailingURLKey=https://app-measurement.com/config/app/1:955410733527:ios:c82bc7afb517ae10479392?platform=ios&app_instance_id=3A4D3A72AC624838AB769B6871063F58&gmp_version=60900, _kCFStreamErrorDomainKey=1}
2020-10-25 10:47:39.194966-0400 test2[2991:36054] 6.34.0 - [Firebase/Analytics][I-ACS901017] Encounter network error. Code, error: -1004, Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo={_kCFStreamErrorCodeKey=61, NSUnderlyingError=0x600001732970 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDownloadTask <69F833DC-E03D-46E7-A72D-DE7246C8BDFF>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=("LocalDownloadTask <69F833DC-E03D-46E7-A72D-DE7246C8BDFF>.<1>"), NSLocalizedDescription=Could not connect to the server., NSErrorFailingURLStringKey=https://app-measurement.com/config/app/1:955410733527:ios:c82bc7afb517ae10479392?platform=ios&app_instance_id=3A4D3A72AC624838AB769B6871063F58&gmp_version=60900, NSErrorFailingURLKey=https://app-measurement.com/config/app/1:955410733527:ios:c82bc7afb517ae10479392?platform=ios&app_instance_id=3A4D3A72AC624838AB769B6871063F58&gmp_version=60900, _kCFStreamErrorDomainKey=1}
2020-10-25 10:47:39.197349-0400 test2[2991:36054] 6.34.0 - [Firebase/Analytics][I-ACS023128] Network request failed to fetch remote config. Code, Error: 0, Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo={_kCFStreamErrorCodeKey=61, NSUnderlyingError=0x600001732970 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDownloadTask <69F833DC-E03D-46E7-A72D-DE7246C8BDFF>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=("LocalDownloadTask <69F833DC-E03D-46E7-A72D-DE7246C8BDFF>.<1>"), NSLocalizedDescription=Could not connect to the server., NSErrorFailingURLStringKey=https://app-measurement.com/config/app/1:955410733527:ios:c82bc7afb517ae10479392?platform=ios&app_instance_id=3A4D3A72AC624838AB769B6871063F58&gmp_version=60900, NSErrorFailingURLKey=https://app-measurement.com/config/app/1:955410733527:ios:c82bc7afb517ae10479392?platform=ios&app_instance_id=3A4D3A72AC624838AB769B6871063F58&gmp_version=60900, _kCFStreamErrorDomainKey=1}
2020-10-25 10:47:39.198538-0400 test2[2991:36054] 6.34.0 - [Firebase/Analytics][I-ACS023129] Network fetch failed. Will retry later. Code, error: 0, Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo={_kCFStreamErrorCodeKey=61, NSUnderlyingError=0x600001732970 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDownloadTask <69F833DC-E03D-46E7-A72D-DE7246C8BDFF>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=("LocalDownloadTask <69F833DC-E03D-46E7-A72D-DE7246C8BDFF>.<1>"), NSLocalizedDescription=Could not connect to the server., NSErrorFailingURLStringKey=https://app-measurement.com/config/app/1:955410733527:ios:c82bc7afb517ae10479392?platform=ios&app_instance_id=3A4D3A72AC624838AB769B6871063F58&gmp_version=60900, NSErrorFailingURLKey=https://app-measurement.com/config/app/1:955410733527:ios:c82bc7afb517ae10479392?platform=ios&app_instance_id=3A4D3A72AC624838AB769B6871063F58&gmp_version=60900, _kCFStreamErrorDomainKey=1}
1- I think everything is going well but it's appearing in the error that you may have a poor connection " Could not connect to the server "
My advice is to try it again and make sure from google Plist that it's documented under the same bundle identifier
2- If the previous doesn't work, just try to update the pod
3- In the worst case try to uninstall it & install it again

iOS 13.4 When app goto background from foreground network is getting disconnect

Steps to reproduce:
Create a new app and call any API to the server to get data
immediately take the app to background
network get disconnects
below is the log:
2020-03-26 17:21:00.894598+0530 TestApp[783:152843] Connection 2: received failure notification
2020-03-26 17:21:00.895805+0530 TestApp[783:152843] Connection 2: failed to connect 1:53, reason -1
2020-03-26 17:21:00.895895+0530 TestApp[783:152843] Connection 2: encountered error(1:53)
2020-03-26 17:21:00.901375+0530 TestApp[783:152843] Task <36B9553A-99F2-42FE-8650-A5E5155EFCFD>.<1> HTTP load failed, 0/0 bytes (error code: -1005 [1:53])
2020-03-26 17:21:00.901831+0530 TestApp[783:152843] Connection 1: received failure notification
2020-03-26 17:21:00.902078+0530 TestApp[783:152843] [] nw_flow_add_write_request [C1.1 40.85.185.46:443 failed channel-flow (satisfied (Path is satisfied), interface: en0, ipv4, dns)] cannot accept write requests
2020-03-26 17:21:00.902200+0530 TestApp[783:152843] [] nw_write_request_report [C1] Send failed with error "Socket is not connected"
2020-03-26 17:21:00.905902+0530 TestApp[783:152870] Task <36B9553A-99F2-42FE-8650-A5E5155EFCFD>.<1> finished with error [-1005] Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={NSUnderlyingError=0x2824734e0 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={_kCFStreamErrorCodeKey=53, _kCFStreamErrorDomainKey=1}}, NSErrorFailingURLStringKey=https://api.server.account, NSErrorFailingURLKey=https://api.server.account, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=53, NSLocalizedDescription=The network connection was lost.}

API request failed on iOS 11.3/11.4 when called through VPN connection

VPN connection created successfully on iOS 10 and also API request executes successfully.
Also, VPN connection created successfully on iOS 11.3 and 11.4 but API request get failed and showing below error:
2018-06-06 15:50:42.366512+0800 myAPP[555:197322] [] nw_path_evaluator_request_nexus_and_stats NECP_CLIENT_ACTION_REQUEST_NEXUS_INSTANCE [65: No route to host]
2018-06-06 15:50:42.366629+0800 myAPP[555:197322] [] nw_endpoint_flow_setup_channel [33 192.168.0.1:8000 in_progress channel-flow (satisfied)] failed to request nexus instance: Error Domain=kNWErrorDomainPOSIX Code=65 "No route to host" UserInfo={NSDescription=No route to host}
2018-06-06 15:50:42.366734+0800 myAPP[555:197322] TIC TCP Conn Failed [18:0x1d0374580]: 1:65 Err(65)
2018-06-06 15:50:42.366808+0800 myAPP[555:197322] Task <2FDCE10C-8CB4-469D-AAE6-E9307A68069D>.<1> HTTP load failed (error code: -1004 [1:65])
2018-06-06 15:50:42.367049+0800 myAPP[555:197506] Task <2FDCE10C-8CB4-469D-AAE6-E9307A68069D>.<1> finished with error - code: -1004
Error-Optional(Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo={NSUnderlyingError=0x1d0650f80
{Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=65, _kCFStreamErrorDomainKey=1}}
Thanks

Resources