2015-11-14 51 views
0

我想實現一個remoteControlWithEvent(在Swift中,iOS 9),但我在我的應用程序委託中出現錯誤。在Swift remoteControlReceivedWithEvent有超類錯誤

我已經在我的viewController下面有這段代碼,並且一切工作都完美無缺。

try AVAudioSession.sharedInstance().setActive(true) 
       print("AVAudioSession is Active") 
       UIApplication.sharedApplication().beginReceivingRemoteControlEvents() 
       self.becomeFirstResponder() 

然而,在我的AppDelegate,如果我嘗試使用功能remoteControlWithEvent,

override func remoteControlReceivedWithEvent(event: UIEvent) { 
     let rc = event.subtype 
     print("does this work? \(rc.rawValue)") 
    } 

我得到的錯誤,「法不從它的超類覆蓋任何方法」。如果我嘗試取消覆蓋,我得到另一個錯誤...

讓我知道如果你能幫助!

-Liam

+0

有什麼其他錯誤? – beyowulf

+0

這是唯一的錯誤。我假設我沒有在我的App Delegate中實現某個超類。 –

+0

是的,func remoteControlReceivedWithEvent(event:UIEvent)是UIResponder的一個方法,AppDelegate是UIResponder的一個子類,所以你不應該得到那個錯誤。我不會在將代碼添加到我的應用程序代理時。檢查你的括號。 – beyowulf

回答

2

其實試試這個:

override func remoteControlReceivedWithEvent(event: UIEvent?) { 
     let rc = event!.subtype 
     print("does this work? \(rc.rawValue)") 
    } 
+0

非常棒,謝謝! –