0
私のイヤホンの再生/一時停止ボタンを押したときに逃げようとしています。このために、私は最初にテキストラベルを変更しようとしています...すぐにイヤホンを使用する
さまざまなウェブサイトを見て、彼らはこれを実行したが動作しません。私の欠けているものはありますか?
私はあなたがオーディオの再生を持っている必要があります任意のRemoteControlEventsについてはviewController.swift
override func viewDidLoad() {
super.viewDidLoad()
canBecomeFirstResponder()
UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBOutlet weak var Cosa: UILabel!
func play() {
Cosa.text = "Play"
}
override func canBecomeFirstResponder() -> Bool {
return true
}
override func remoteControlReceivedWithEvent(event: UIEvent?) {
guard let event = event else {
print("no event\n")
return
}
guard event.type == UIEventType.RemoteControl else {
print("received other event type\n")
return
}
switch event.subtype {
case UIEventSubtype.RemoteControlPlay:
print("received remote play\n")
play()
case UIEventSubtype.RemoteControlPause:
print("received remote pause\n")
case UIEventSubtype.RemoteControlTogglePlayPause:
print("received toggle\n")
default:
print("received \(event.subtype) which we did not process\n")
}
}
については、以下のリンクを参照することができますが、コードのコメント:あなたのIBOutlet「コーザは」で始まる必要があります小文字。大文字で始まるObj-cとSwiftの名前は、型であると予想されます。メンバーの値、プロパティ、メソッドはすべて小文字で始まる必要があります。 – alexkent