Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
622 views
in Technique[技术] by (71.8m points)

iphone - remoteControlReceivedWithEvent not Called in appDelegate

I'm having problem to control the iPhone controls with my avplayer.

if I put the function

- (void)remoteControlReceivedWithEvent:(UIEvent *)event

in the view controller that responsible for playing the function called but only if I i'm going to background in the current view controller.

if i'm going to background from other view controller the function never called.

that's why i want to put it in the app delegate.

I tried Becomefirstresponse and to put the function in every view controller but it did help.

also I call

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

in the

-(void)applicationWillResignActive:(UIApplication *)application

thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have used below code to iPhone Control -

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];

Used to get register for listening the remote control. Once done remove it -

[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];

make the App canBecomeFirstResponder-

- (BOOL)canBecomeFirstResponder {
    return YES;
}

Used delegate method to handle iPhone control, like play and pause while doble tap on the home button

- (void)remoteControlReceivedWithEvent:(UIEvent *)event {
    //if it is a remote control event handle it correctly
    if (event.type == UIEventTypeRemoteControl) {
        if (event.subtype == UIEventSubtypeRemoteControlPlay) {
           [audioPlayer play];
            NSLog(@"play");
        } else if (event.subtype == UIEventSubtypeRemoteControlPause) {
           [audioPlayer stop];
             NSLog(@"pause");
        } else if (event.subtype == UIEventSubtypeRemoteControlTogglePlayPause) {
            NSLog(@"toggle");
        }
    }
}

In my case i am able to handle play and pause.Please let know if any thing wrong.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...