Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private func subscribeToGeoTracks(args: Dictionary<String, Any>, flutterResult: @escaping FlutterResult) {
- do {
- let subscriptionKey = UUID().uuidString
- let userId = args["userId"] as! Int
- let subscription = NotifiedByLocationLambdaSubscription(userId: userId)
- let watcher = try self.client!.subscribe(subscription: subscription, resultHandler: ({ (result, transaction, error) in
- if error != nil {
- self.channel.invokeMethod(subscriptionKey + "@" + AppSyncPlugin.SUBSCRIBE_TO_GEO_TRACKS_ERROR,
- arguments: error!.localizedDescription)
- } else {
- if let _ = result!.data?.notifiedByLocationLambda {
- let values = result!.data!.snapshot
- do {
- let jsonData = try JSONSerialization.data(withJSONObject: values, options: .prettyPrinted)
- let convertedString = String(data: jsonData, encoding: String.Encoding.utf8)
- self.channel.invokeMethod(subscriptionKey + "@" + AppSyncPlugin.SUBSCRIBE_TO_GEO_TRACKS_RESULT, arguments: convertedString)
- } catch {
- flutterResult(FlutterError(code: "APP_ERROR", message: error.localizedDescription, details: nil))
- }
- }
- }
- }))
- geoTracksSubscriptions[subscriptionKey] = watcher
- flutterResult(subscriptionKey)
- } catch {
- flutterResult(FlutterError(code: "QUERY_ERROR", message: error.localizedDescription, details: nil))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement