关于扩展的成员的模糊引用

时间:2017-09-24 20:05:24

标签: swift tokbox

我使用TokBox api。我想使用信号方法。但我得到了成员会议的不明确的参考'错误。

这是代码:

ERROR in ./node_modules/react-native-svg/lib/SvgTouchableMixin.js
Module not found: Error: Can't resolve 'react-native/Libraries/Components/Touchable/Touchable' in '/home/payalverma/Projects/caro-mobile/node_modules/react-native-svg/lib'
@ ./node_modules/react-native-svg/lib/SvgTouchableMixin.js 1:296-360
@ ./node_modules/react-native-svg/elements/Shape.js
@ ./node_modules/react-native-svg/elements/Rect.js
@ ./node_modules/react-native-svg/index.js
@ ./app/components/common/DrawerContent.js
@ ./app/components/Home.js
@ ./app/components/routes/Navigation.web.js
@ ./app/index.js
@ ./index.web.js
@ multi (webpack)-dev-server/client?http://0.0.0.0:5000 webpack/hot/dev-server ./index.web.js

我有import UIKit import OpenTok import Firebase import FontAwesome_swift class CallView: UIViewController { private var session: OTSession? private var publisher : CustomPublisher? override func viewDidLoad() { super.viewDidLoad() //connect to the session connectToAnOpenTokSession() } func connectToAnOpenTokSession() { session = OTSession(apiKey: "xxx", sessionId: "xxx", delegate: self) var error: OTError? session?.connect(withToken: "xxx", error: &error) if error != nil { print(error!) } } } extension CallView: OTSessionDelegate { func sessionDidConnect(_ session: OTSession) { print("The client connected to the OpenTok session.") var error: OTError? = nil defer { print(error.debugDescription) } } func chat(){ var error: OTError? = nil try? session!.signal(withType: "chat", string: "bla", connection: nil) if error != nil { print("Signal error: \(error)") } else { print("Signal sent: ") } } func sessionDidDisconnect(_ session: OTSession) { print("The client disconnected from the OpenTok session.") } func session(_ session: OTSession, didFailWithError error: OTError) { print("The client failed to connect to the OpenTok session: \(error).") } func session(_ session: OTSession, streamCreated stream: OTStream) { print("A stream was created in the session.") } func session(_ session: OTSession, streamDestroyed stream: OTStream) { print("A stream was destroyed in the session.") } } extension CallView: OTPublisherDelegate { func publisher(_ publisher: OTPublisherKit, didFailWithError error: OTError) { print("The publisher failed: \(error)") } } 方法。但是我在这一行得到了对成员错误的不明确的引用:

尝试? session!.signal(withType:" chat",string:" bla",connection:nil)

我不知道如何修复它。我试过chat(),因为我认为它超出了范围。

导致此问题的原因是什么?如何解决?

1 个答案:

答案 0 :(得分:1)

尝试将OTError实例附加到函数的参数中。

另外,请避免使用强制解包和未处理的错误捕获。

guard let tokSession = session else {
    return
}

do {
    var error: OTError? = nil
    try tokSession.signal(withType: "chat", string: "bla", connection: nil, error: error)

    if error != nil {
        print("Signal error: \(error)")
    } else {
        print("Signal sent: ")
    }
} catch let error {
    print(error.localizedDescription)
}