我的應用程序中有2個ViewController。在每個視圖控制器中處理遠程控制事件
ViewController1播放音頻和ViewController2顯示了一些文字。
我想用遙控器來控制音頻,當我在ViewController2我。例如,用戶在ViewController2中並想停止音頻。
我的代碼:
ViewController1.m完美的作品
- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent
{
MARK;
if (receivedEvent.type == UIEventTypeRemoteControl) {
switch (receivedEvent.subtype) {
case UIEventSubtypeRemoteControlTogglePlayPause:
DLog(@"remotecontrol_toggle");
[self togglePlayPause];
break;
case UIEventSubtypeRemoteControlPause:
DLog(@"remotecontrol_pause");
[self pause];
break;
case UIEventSubtypeRemoteControlPlay:
DLog(@"remotecontrol_play");
[self play];
break;
case UIEventSubtypeRemoteControlStop:
DLog(@"remotecontrol_stop");
[self stop];
break;
default:
break;
}
}
}
我的問題是,什麼是把這一切放在一起最好的方法是什麼?我必須在ViewController2中處理事件嗎?
我知道,在AppDelegate.m,我可以這樣做:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
MARK;
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
}
- (void)applicationWillTerminate:(UIApplication *)application
{
MARK;
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
}
這樣一來,我的應用程序中控制每個視圖遙控器,但由於接收到的事件AREN不解決我的問題在ViewController2中沒有處理。
但我不能把收到AppDelegate.m事件,所以我得把每一個視圖控制器的事件?
我是新來的iOS開發,不知道是不是我想就在這裏。
任何幫助表示讚賞。
感謝您的回答,但現在,我不認爲我需要這種複雜性。我的應用很簡單,我只想在當前的環境中處理事件。 –