Created
November 6, 2018 21:46
-
-
Save standinga/396120434ee1c00adff059d10008bd8c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AppDelegate.swift | |
// RemoteReceiver | |
// Receive remote events from Bluetooth head set or player. | |
// Created by michal on 06/11/2018. | |
// Copyright © 2018 michal. All rights reserved. | |
// | |
import UIKit | |
import MediaPlayer | |
import AVFoundation | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
var myApplication: UIApplication! | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
try! AVAudioSession.sharedInstance() | |
.setCategory(AVAudioSession.Category.playback, | |
mode: AVAudioSession.Mode.default) | |
try! AVAudioSession.sharedInstance().setActive(true, options: []) | |
let mrcc = MPRemoteCommandCenter.shared() | |
mrcc.playCommand.addTarget { (event) -> MPRemoteCommandHandlerStatus in | |
print(event) | |
return .success | |
} | |
mrcc.togglePlayPauseCommand.addTarget { event -> MPRemoteCommandHandlerStatus in | |
print(event) | |
return .success | |
} | |
mrcc.stopCommand.addTarget { event -> MPRemoteCommandHandlerStatus in | |
print(event) | |
return .success | |
} | |
mrcc.nextTrackCommand.addTarget { event in | |
print(event) | |
return .success | |
} | |
mrcc.previousTrackCommand.addTarget { event in | |
print (event) | |
return .success | |
} | |
return true | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Receive remote events from Bluetooth head set or player.