Swift 添加 ATTrackingManager - 在 info.plist 中找不到密钥
Swift add ATTrackingManager - cannot find key in info.plist
我正在尝试将 ATTrackingManager 添加到 IOS 项目,我不是 Swift 开发人员,所以一步一步地阅读了一些文档,理论上我所做的一切都是正确的,但应用程序仍然崩溃。
所以基本上我做了这样的事情:
func handleTrackingAuth() {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
switch status {
case .notDetermined:
print("ATTrackingManagerAuthorizationStatusNotDetermined", status)
break
case .restricted:
print("ATTrackingManagerAuthorizationStatusRestricted", status)
break
case .denied:
print("ATTrackingManagerAuthorizationStatusDenied", status)
break
case .authorized:
print("ATTrackingManagerAuthorizationStatusAuthorized", status)
break
@unknown default:
print("ATTracking no data", status)
break
}
}
}
}
并将其添加到 applicationDidBecomeActive 部分。
然后我用正确的密钥更新了我的 GoogleService-Info.plist:
<key>NSUserTrackingUsageDescription</key>
<string>This app needs permission to track you across apps and websites owned by 3rd parties.</string>
但应用程序仍然因错误而崩溃
This app has crashed because it attempted to access privacy-sensitive
data without a usage description. The app's Info.plist must contain
an NSUserTrackingUsageDescription key with a string value explaining
to the user how the app uses this data.
我想也许 Xcode 没有刷新文件,所以我清理了构建文件夹并重新启动 Xcode 但仍然得到同样的错误。有谁知道为什么它没有检测到添加了密钥?
对于NSUserTrackingUsageDescription
,类型应该是string
。
在图片中,类型显示的是一个数组。它应该是一个字符串。
我正在尝试将 ATTrackingManager 添加到 IOS 项目,我不是 Swift 开发人员,所以一步一步地阅读了一些文档,理论上我所做的一切都是正确的,但应用程序仍然崩溃。
所以基本上我做了这样的事情:
func handleTrackingAuth() {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
switch status {
case .notDetermined:
print("ATTrackingManagerAuthorizationStatusNotDetermined", status)
break
case .restricted:
print("ATTrackingManagerAuthorizationStatusRestricted", status)
break
case .denied:
print("ATTrackingManagerAuthorizationStatusDenied", status)
break
case .authorized:
print("ATTrackingManagerAuthorizationStatusAuthorized", status)
break
@unknown default:
print("ATTracking no data", status)
break
}
}
}
}
并将其添加到 applicationDidBecomeActive 部分。
然后我用正确的密钥更新了我的 GoogleService-Info.plist:
<key>NSUserTrackingUsageDescription</key>
<string>This app needs permission to track you across apps and websites owned by 3rd parties.</string>
但应用程序仍然因错误而崩溃
This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSUserTrackingUsageDescription key with a string value explaining to the user how the app uses this data.
我想也许 Xcode 没有刷新文件,所以我清理了构建文件夹并重新启动 Xcode 但仍然得到同样的错误。有谁知道为什么它没有检测到添加了密钥?
对于NSUserTrackingUsageDescription
,类型应该是string
。
在图片中,类型显示的是一个数组。它应该是一个字符串。