如何解决 NSAppleMusicUsageDescription 错误

How to resolve NSAppleMusicUsageDescription error

我目前运行在我自己的设备上安装我的应用程序。目标是播放本地保存在音乐应用程序中的歌曲。我导入 MediaPlayer 并尝试执行以下

            MPMediaLibrary.requestAuthorization { (status) in
                if status == .authorized {
                    print("authorized")
                }
            }

我的 Info.plist 如下所示

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>NSAppleMusicUsageDescription</key>
    <string>This app requires access to play music</string>
</dict>
</plist>

然而,每当我 运行 我设备上的应用程序时,它立即崩溃并给我

This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSAppleMusicUsageDescription key with a string value explaining to the user how the app uses this data.

我错过了什么?

原来有多个Info.plist...我在看目录下的那个,很容易发现的那个。

相反,您需要通过转到顶部的“项目设置”->“信息”选项卡来访问正确的 plist。在那里添加它。