Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to separate for remoteControlEvents #10

Open
anishroff opened this issue Apr 11, 2017 · 1 comment
Open

How to separate for remoteControlEvents #10

anishroff opened this issue Apr 11, 2017 · 1 comment

Comments

@anishroff
Copy link

I tried this to separate remoteControlEvents and my code looks like

import Foundation
import PluggableApplicationDelegate

final class MusicControlsAppService: NSObject, ApplicationService {
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
        UIApplication.shared.beginReceivingRemoteControlEvents()
        print("It has started!")
        return true
    }
    
    func applicationDidEnterBackground(_ application: UIApplication) {
        print("It has entered background")
    }
    
    override func remoteControlReceived(with event: UIEvent?) {
        if event?.type == .remoteControl {
            switch event!.subtype {
            case .remoteControlPlay:
                PlayerManager.shared.playTapped()
            case .remoteControlPause:
                PlayerManager.shared.pauseTapped()
            case .remoteControlTogglePlayPause:
                if PlayerManager.shared.isPauseActive {
                    PlayerManager.shared.playTapped()
                } else {
                    PlayerManager.shared.pauseTapped()
                }
            case .remoteControlNextTrack:
                PlayerManager.shared.nextTapped()
            case .remoteControlPreviousTrack:
                PlayerManager.shared.previousTapped()
            default:
                break
            }
        }
    }
}

This gives error for the method Method does not override any method from its superclass , also when override keyword is removed it doesn't get calls.

Can you assist to solve this ? As of now I am keeping that method in the main App delegate which is subclass of PluggableApplicationDelegate which works.

@NikolayShubenkovProgSchool

This is due to method -remoteControlReceived is not implemented in pluggableApplicationDelegate and it is not redirects is to any service.
To make this work in your appDelegate override this method like this:

override func remoteControlReceived(with event: UIEvent?) {
services.forEach{ if let service = $0 as? UIResponder {
service.remoteControlRecieved(with event)
}
}
}

you should some how store initialized services to prevent recreating them on every call of services property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants