Skip to content

Instantly share code, notes, and snippets.

@standinga
Created November 6, 2018 21:46
Show Gist options
  • Save standinga/396120434ee1c00adff059d10008bd8c to your computer and use it in GitHub Desktop.
Save standinga/396120434ee1c00adff059d10008bd8c to your computer and use it in GitHub Desktop.
//
// 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
}
}
@standinga
Copy link
Author

Receive remote events from Bluetooth head set or player.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment