1

I am trying to implement Amazon FireTV's code via a Bridge from react-native. My goal is to send a signal to the remote player, then resolve the RCTPromiseResolveBlock so that in my javascript I can await the function.

@objc func fling(_ options: NSDictionary, _ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
  let player = getDeviceFromUuid(uuid:uuid) // instance of RemoteMediaPlayer
  // ... more code
  let bftask = player?.setMediaSourceToURL(
    url,
    metaData:metaData,
    autoPlay:true,
    andPlayInBackground:false)

  bftask?.continue({ (task:BFTask) -> Void in
    if task.error != nil {
      reject() // <-- These are "non-escaping parameters captured in an escaping closure"
    } else {  
      resolve() // <-- 
    }
  })

The above code throws Escaping closure captures non-escaping parameter. How do I allow reject & resolve to be available in the closure? Or more broadly, how do I execute the asynchronous request setMediaSourceToURL, wait for it's completion, and then resolve the promise block?

For reference, BFTask is an artifact of https://github.com/facebookarchive/Bolts-ObjC . It's interface suggests the following:

BFTask Interface options

I look to you, wizards of the IOS world.

jbodily
  • 3,613
  • 2
  • 20
  • 21

1 Answers1

2

Okay. Just had to add @escaping to the arguments:

@objc func fling(_ options: NSDictionary, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
...
jbodily
  • 3,613
  • 2
  • 20
  • 21