Advertisement
brooth

Untitled

Oct 28th, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.72 KB | None | 0 0
  1.  
  2.     private func subscribeToGeoTracks(args: Dictionary<String, Any>, flutterResult: @escaping FlutterResult) {
  3.         do {
  4.             let subscriptionKey = UUID().uuidString
  5.             let userId = args["userId"] as! Int
  6.             let subscription = NotifiedByLocationLambdaSubscription(userId: userId)
  7.             let watcher = try self.client!.subscribe(subscription: subscription, resultHandler: ({ (result, transaction, error) in
  8.                 if error != nil {
  9.                     self.channel.invokeMethod(subscriptionKey + "@" + AppSyncPlugin.SUBSCRIBE_TO_GEO_TRACKS_ERROR,
  10.                                               arguments: error!.localizedDescription)
  11.                 } else {
  12.                     if let _ = result!.data?.notifiedByLocationLambda {
  13.                         let values = result!.data!.snapshot
  14.                         do {
  15.                             let jsonData = try JSONSerialization.data(withJSONObject: values, options: .prettyPrinted)
  16.                             let convertedString = String(data: jsonData, encoding: String.Encoding.utf8)
  17.                             self.channel.invokeMethod(subscriptionKey + "@" + AppSyncPlugin.SUBSCRIBE_TO_GEO_TRACKS_RESULT, arguments: convertedString)
  18.                         } catch {
  19.                             flutterResult(FlutterError(code: "APP_ERROR", message: error.localizedDescription, details: nil))
  20.                         }
  21.                     }
  22.                 }
  23.             }))
  24.             geoTracksSubscriptions[subscriptionKey] = watcher
  25.             flutterResult(subscriptionKey)
  26.         } catch {
  27.             flutterResult(FlutterError(code: "QUERY_ERROR", message: error.localizedDescription, details: nil))
  28.         }
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement