[ad_1]
In my iOS app, I play music and I need to add a notification permitting the person to regulate the audio participant.
So here’s what I attempted with MPRemoteCommandCenter:
override func software(
_ software: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{
UNUserNotificationCenter.present().requestAuthorization(choices: [.alert, .badge]) { [self] (granted, error) in
if (granted)
{
self.initNotification(software)
}
else
{
print("Notifications permission denied as a result of: (error?.localizedDescription).")
}
}
// ...
return tremendous.software(software, didFinishLaunchingWithOptions: launchOptions)
}
non-public func initNotification(_ software: UIApplication)
{
software.beginReceivingRemoteControlEvents()
MPRemoteCommandCenter.shared().playCommand.isEnabled = true
MPRemoteCommandCenter.shared().playCommand.addTarget { occasion in
return .success
}
var nowPlayingInfo = [String: Any]()
nowPlayingInfo[MPMediaItemPropertyTitle] = "Film Title"
nowPlayingInfo[MPMediaItemPropertyArtist] = "Artist Identify"
MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
}
It compiles and run, however for some cause, no notification seems on the display.
What did I neglect?
Thanks.
[ad_2]
