remoteControlReceivedWithEvent called on iOS 7.0 device but not iOS 8.0

后端 未结 2 662
情深已故
情深已故 2021-01-18 21:41

I have an application that plays audio in the background. I am trying to fix a bug where the audio controls (play/pause), on the home screen (etc.), DO NOT work on iOS 8.0+

2条回答
  •  礼貌的吻别
    2021-01-18 22:36

    Finally figured out the issue I was having. Ultimately it seemed that the events from the Remote Control on the home screen were never making it into my app and down to my view controllers. I ended up subclassing the UIWindow so that I could see what events were making their way through the chain. As UIWindow is a UIResponder I also added the - (void)remoteControlReceivedWithEvent:(UIEvent *)event to the subclass. Then in the makeKeyAndVisible I added the:

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

    I started up the debugger and the -(void)makeKeyAndVisible was never called! I then searched my app delegate for the window member variable and the [window makeKeyAndVisible]; line was nowhere to be found! I added it back in (as it should have been there) and presto events are routing to the correct locations like magic. Why this was working on some versions of iOS and not others and without any other noticeable issues is beyond me.

    Hope this helps someone out in the future.

提交回复
热议问题