gpt4 book ai didi

ios - Apple Music Api——检测 Apple Music 订阅不工作

转载 作者:行者123 更新时间:2023-11-28 23:38:33 26 4
gpt4 key购买 nike

Apple 在 StoreKit 框架中提供了一种方法来检测用户是否订阅了 Apple Music,但它根本不起作用。我订阅了 Apple Music,既可以在我的应用程序内收听歌曲,也可以从我的应用程序内将项目添加到我的资料库中——但是,当我请求我的功能时,它并没有说我有。这是我的代码:

let serviceController = SKCloudServiceController()
serviceController.requestCapabilities { (capability:SKCloudServiceCapability, err:Error?) in
print("error in capability check is \(err)")
switch capability {
case SKCloudServiceCapability.musicCatalogPlayback:
print("user has Apple Music subscription and can play music from apple music api")
case SKCloudServiceCapability.addToCloudMusicLibrary:
print("user has an Apple Music subscription, can play music from api, also can add to their music library")
case SKCloudServiceCapability.musicCatalogSubscriptionEligible:
print("user does not have subscription")
default:
print("default and capability is \(capability.rawValue)")
}
}

每次我运行我的应用程序时,它都会打印“默认和功能为 257”。我已经尝试卸载/重新安装大概十几次了——每次都一样。

请注意,我确实可以通过 Apple Music api 获取我的用户 token 并将歌曲添加到我的音乐库中。

有没有其他人遇到过这种情况,是否有另一种解决方法来查看用户是否订阅了 Apple Music?

最佳答案

capability 是一个 OptionSet,因为用户可能具有 musicCatalogPlaybackaddToCloudMusicLibrary 或同时具有这两种功能。

您看到的原始值是实际值的按位OR,因为正如您所说,您拥有这两种功能。

您可以使用一系列 if 语句或特定的 if 语句来检查您需要的功能:

let serviceController = SKCloudServiceController()
serviceController.requestCapabilities { (capability:SKCloudServiceCapability, err:Error?) in
guard err == nil else {
print("error in capability check is \(err!)")
return
}

if capability.contains(SKCloudServiceCapability.musicCatalogPlayback) {
print("user has Apple Music subscription and can play music from apple music api")
}

if capability.contains(SKCloudServiceCapability.addToCloudMusicLibrary) {
print("user has an Apple Music subscription, can play music from api, also can add to their music library")
}

if capability.contains(SKCloudServiceCapability.musicCatalogSubscriptionEligible) {
print("user does not have subscription")
}
}

给予

user has Apple Music subscription and can play music from apple music api

user has an Apple Music subscription, can play music from api, also can add to their music library

关于ios - Apple Music Api——检测 Apple Music 订阅不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54175721/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com