John-Lluch / SWRevealViewController

A UIViewController subclass for presenting side view controllers inspired on the FaceBook and Wunderlist apps, done right !
Other
4.52k stars 988 forks source link

How to make remote controls to work? #414

Open thefenix1 opened 9 years ago

thefenix1 commented 9 years ago

Since I added this component to my project, lock screen media controls quit working. Method "remoteControlReceivedWithEvent" is not called anymore on my view controller. I'd say it's not surprising since "SWRevealViewController" becomes root controller.

I'm not sure how to make this work again. Maybe is something easy and I'm not seeing it. Could you help me with this?

Thanks

thefenix1 commented 9 years ago

Do anyone could help me with this if I provide more details? Not sure if my quesiton is not clear enough , Thanks for the great work with this component.

thefenix1 commented 9 years ago

Unfortunately I didn't find any way to make this work so I had to change component code. If this is the correct way to do it, would be great to see it integrated to the repository. There may be better ways though.

Changes on "SWRevealViewController.m"

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

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

- (void)viewWillDisappear:(BOOL)animated
{
    [[UIApplication sharedApplication] endReceivingRemoteControlEvents];
    [self resignFirstResponder];

    [super viewWillDisappear:animated];
}

- (void)remoteControlReceivedWithEvent:(UIEvent *)event {
    switch (event.subtype) {
        case UIEventSubtypeRemoteControlPlay:
            [[NSNotificationCenter defaultCenter] postNotificationName:kSWRemoteControlPlay object:self];
            break;
        case UIEventSubtypeRemoteControlPause:
            [[NSNotificationCenter defaultCenter] postNotificationName:kSWRemoteControlPause object:self];
            break;
        default:
            break;
    }
}

constants definition

NSString *const kSWRemoteControlPause = @"SWRemoteControlPause";
NSString *const kSWRemoteControlPlay = @"SWRemoteControlPlay";

Changes on "SWRevealViewController.h"

extern NSString *const kSWRemoteControlPause;
extern NSString *const kSWRemoteControlPlay;