
import SAPOfflineOData
func getProductsOffline(_ serviceRoot: URL, _ urlSession: SAPURLSession) {
var storeParams: OfflineODataParameters = OfflineODataParameters()
storeParams.storeName = "ESPMOfflineDB"
do {
let oDataProvider = try OfflineODataProvider(serviceRoot: serviceRoot, parameters: storeParams, sapURLSession: urlSession)
let espmContainer = ESPMContainer(provider: oDataProvider)
let productsDQ = OfflineODataDefiningQuery(name: "ProductsQuery", query: "Products", automaticallyRetrievesStreams: false)
try oDataProvider.add(definingQuery: productsDQ)
oDataProvider.open(completionHandler: { ( _ error: OfflineODataError? ) -> Void in
if (error == nil) {
print("Store successfully opened")
espmContainer.fetchProducts() { products, error in
guard let products = products else {
self.logger.error("Error fetching products: \(error!.localizedDescription)")
return
}
print("Offline: got \(products.count) products and the first product name is \(products[0].name!)")
//try! oDataProvider.close()
}
} else {
self.logger.error("Store open failed")
}
} )
}
catch {
logger.error(error.localizedDescription)
}
}
getProductsOffline(serviceURL, myContext.sapURLSession)
Button pressed 1 times
Currently connected by WiFi
Got 123 products and the first product name is Surround Sound
Store successfully opened
Offline: got 123 products and the first product name is Gaming Monster Pro
Button pressed 1 times
Currently offline with no network connection
2017-11-11 14:31:21.046636-0500 GettingStarted[48051:2665101] TIC TCP Conn Failed [2:0x608000362280]: 1:50 Err(50)
2017-11-11 14:31:21.047412-0500 GettingStarted[48051:2665101] Task FB2FEB2D-4415-4830-B894-B1027975BDA1. 2 HTTP load failed (error code: -1009 [1:50])
2017-11-11 14:31:21.047595-0500 GettingStarted[48051:2666620] Task FB2FEB2D-4415-4830-B894-B1027975BDA1. 2 finished with error - code: -1009
Error fetching products: Optional(HTTPError: The Internet connection appears to be offline.)
Store successfully opened
Offline: 123 products and the first product name is Gaming Monster Pro
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
13 | |
12 | |
11 | |
10 | |
10 | |
9 | |
8 | |
8 | |
8 | |
7 |