Offline mutation not working when sim card is present in iphone
shreyapohekar opened this issue · 6 comments
Describe the bug
When i use a feature in offline mode without sim, it correctly sync when the device gets online via wifi. But when sim card is present and the feature is used in offline mode i see an error when the I create things in offline. So when the device is back online, the data never syncs as the mutation was not created.
When sim card is not present, I get this in the logs (error code -1009)
Task <D5BACDB2-1E0F-46D6-B37A-4461FB67AD4F>.<153> finished with error [-1009] Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={_kCFStreamErrorCodeKey=50, NSUnderlyingError=0x2812350e0 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <D5BACDB2-1E0F-46D6-B37A-4461FB67AD4F>.<153>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <D5BACDB2-1E0F-46D6-B37A-4461FB67AD4F>.<153>"
), NSLocalizedDescription=The Internet connection appears to be offline., NSErrorFailingURLStringKey=https://lvct7kcjwfh.appsync-api.us-east-1.amazonaws.com/graphql, NSErrorFailingURLKey=https://lvct7kcjwfh2le.appsync-api.us-east-1.amazonaws.com/graphql, _kCFStreamErrorDomainKey=1}
When sim card is present, I get an error (error code -1020)
Optional(AWSAppSync.AWSAppSyncClientError.requestFailed(nil, nil, Optional(Error Domain=NSURLErrorDomain Code=-1020 "A data connection is not currently allowed." UserInfo={_kCFStreamErrorCodeKey=50, NSUnderlyingError=0x280d72940 {Error Domain=kCFErrorDomainCFNetwork Code=-1020 "(null)" UserInfo={_kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <8FCAAA75-2607-4B88-B99E-86E4A9E93F82>.<319>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <8FCAAA75-2607-4B88-B99E-86E4A9E93F82>.<319>"
), NSLocalizedDescription=A data connection is not currently allowed., NSErrorFailingURLStringKey=https://lvct7kcjwfh2.appsync-api.us-east-1.amazonaws.com/graphql, NSErrorFailingURLKey=https://lvct7kcjwfh2.appsync-api.us-east-1.amazonaws.com/graphql, _kCFStreamErrorDomainKey=1})))
Code block that generates the error
let cancellable = self.appSyncClient.perform(mutation: ActivityMutation, optimisticUpdate: { (transaction) in
log(LogEvents.Activity.cache)
if let transaction = transaction {
_ = self.createActivityInCache(transaction: transaction, wActivity: _wActivity, OrderId: _wActivity.OrderId!)
.subscribe(onNext: {_ in
observer.onNext(id)
observer.onCompleted()
})
}else{
observer.onError("Failed to create activity in cache")
}
}, resultHandler: { (result, error) in
if checkError(error, logType: LogEvents.Activity.self) ||
checkError(result?.errors, logType: LogEvents.Activity.self) {
print("my error",error, result)
return
}
In the print statement (my error), above error is obtained and result is nil
To Reproduce
Steps to reproduce the behavior:
- Insert sim card and use the app in offline mode
- After doing the work in offline, turn on wifi
- Nothing syncs
Expected behavior
The data should sync even when the sim card is present
Environment(please complete the following information):
- AppSync SDK Version: [3.3.1]
- Dependency Manager: [Carthage]
- Swift Version : [ 5.0]
Device Information (please complete the following information):
- Device: [iphone 12]
- iOS Version: [ios 15]
Any help on how presence of sim cards are handled in offline capabilities of appsync would be much appreciated.
Looks like a duplicate issue, please check the response here #427 (comment)
Looking at the error log it look like the error kCFURLErrorDataNotAllowed = -1020
is coming from the network itself.
https://developer.apple.com/documentation/cfnetwork/cfnetworkerrors/kcfurlerrordatanotallowed?language=objc.
I am suspecting that while the network switch occurs the device might be momentarily in a no data state which stops the app from syncing. Few questions to further debug the error:
- Does the SIM card has data enabled? If not, will you be able to test this with sim card with data enabled?
- How are you switching between offline and online mode? Manually turning the wifi on/off?
- Does the data get synced eventually?
Also, as stated in the comment above, we recommend using Datastore if this is a new project - https://docs.amplify.aws/lib/datastore/sync/q/platform/ios/
Answer to : I am suspecting that while the network switch occurs the device might be momentarily in a no data state which stops the app from syncing.
I get that error (requestfailed) in offline creation of stuff only. So if something is not created on offline, it will never sync when goes online.
- yes the sim card has data enabled. When the sim data is turned on, the device goes online and everything works fine.
- yes I turn the wifi on or off to go online and offline. ( the prob also arise here only. Going online/offline by toggling airplane mode works fine)
- Once the device gets online, the data starts to sync. It takes a few seconds to complete the syncing.
Its not a new project so cant use datastore.
Thank you for the info, we will try to reproduce this from our side and check if there is something missing from the SDK side.
Any resolution for this issue? we are also facing a similar issue, sometimes the offline records are not synced when we get the connection back.
Thank you for opening this issue. AWS AppSync SDK for iOS entered maintenance mode in September 2023 and will receive no further updates as of September 2024.
Please use Amplify Swift going forward. For information on upgrading to Amplify Swift, refer to the Upgrade from AppSync SDK documentation.