我现在在尝试上传到应用商店时遇到此错误,但我没有对我的 healthkit 功能进行任何更改,而且一切看起来都很好(参见图片)。为什么说价值是[] 
<
?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.developer.healthkit</key>
<true/>
<key>com.apple.developer.healthkit.access</key>
<array/>
<key>com.apple.developer.icloud-container-identifiers</key>
<array>
<string>iCloud.codes.myndarc.newFitnessApp</string>
</array>
<key>com.apple.developer.icloud-services</key>
<array>
<string>CloudKit</string>
</array>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.myndarc.newFitnessApp</string>
</array>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
我想检查HeathKit是否已被授权我读取用户的数据,如果我被授权进行训练,如果没有弹出警报.但requestAuthorizationToShareTypes似乎总是返回true?如何获得用户是否授权我的参考?
override func viewDidLoad() {
super.viewDidLoad()
//1. Set the types you want to read from HK Store
let healthKitTypesToRead: [AnyObject?] = [
HKObjectType.workoutType()
]
//2. If the store is not available (for instance, iPad) return an error and don't go on.
if !HKHealthStore.isHealthDataAvailable() {
let error = NSError(domain: "com.myndarc.myrunz", code: 2, userInfo: [NSLocalizedDescriptionKey: "HealthKit is not available in this Device"])
print(error)
let alertController = UIAlertController(title: "HealthKit Not Available", message: "It doesn't look like HealthKit is available on your device.", preferredStyle: …Run Code Online (Sandbox Code Playgroud) 访问MPMusicPlayerController.systemMusicPlayer()(下面的代码)有助于获取Apple Music应用程序中正在播放的内容的跟踪信息,但有没有办法可以访问Spotify应用中播放的当前歌曲的信息?
这个代码张贴在这个答案我需要知道如何获取有关该玩家当前流(播放器,Spotify的,Napster公司...)信息使用MPNowPlayingInfoCenter是无是否使用苹果公司的音乐或Spotify的等.
let player = MPMusicPlayerController.systemMusicPlayer()
@IBAction func getMusicButton(_ sender: UIButton) {
if let mediaItem = player.nowPlayingItem {
let title: String = mediaItem.value(forProperty: MPMediaItemPropertyTitle) as! String
let albumTitle: String = mediaItem.value(forProperty: MPMediaItemPropertyAlbumTitle) as! String
let artist: String = mediaItem.value(forProperty: MPMediaItemPropertyArtist) as! String
print("\(title) on \(albumTitle) by \(artist)")
}
}
Run Code Online (Sandbox Code Playgroud) 我在我的手表应用程序的控制台中收到此错误,我无法弄清楚它与之相关的内容,也没有找到任何其他帖子或文档.其他人都知道吗?
完整信息是2017-12-02 18:31:01.379382-0500 Watch Extension [1308:33925] [default] containerAppExtensionEntitlementsWithCompletion:失败并显示错误:(null)
我已阅读所有有关支持动态文本大小的文章,但我的问题是我有一个由形状和一些文本组成的视图。我需要对此视图的高度进行硬编码,因此当用户使用较大的文本大小时,文本会与形状重叠。我想做的是检测何时使用较大的文本大小并增加视图的硬编码高度。
我试图跟踪用户在 SwiftUI 中所在的页面,TabView但PageTabViewStyle我无法找出跟踪页面索引的最佳方法?using.onAppear效果不佳,因为它会被多次调用,并且即使不在屏幕上,页面 2 和 3 也会被调用。
@State var pageIndex = 0
var body: some View {
VStack {
Text("current page = \(0) ")
TabView {
Text("First")
.onAppear {
pageIndex = 0
}
Text("Second")
.onAppear {
pageIndex = 1
}
Text("Third")
.onAppear {
pageIndex = 2
}
}
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
}
}
}
Run Code Online (Sandbox Code Playgroud) 这只是今天在 Xcode 15 中开始的。我还没有添加任何新的日志或打印语句,但是当我在 iPhone 14 Pro 上构建并运行时,我点击应用程序中的视图,控制台正在打印:
1 条日志/路标消息由于实时模式录制中的高速率而丢失。为了保证所有日志的传送,请在可执行文件的环境中将 IDELogRedirectionPolicy 设置为 oslogToStdio。
无数次。当我在 iPhone 13 mini 上构建并运行完全相同的代码时,它不起作用?
我到处都看,包括Apple的示例应用程序.但是当我可以在不需要在电话上运行任何代码的情况下请求位置时,我找不到任何地方,在"接口控制器"中使用下面的代码返回"未确定"状态.我确实检查了我的info.plist是否设置了隐私密钥值.
import Foundation
import CoreLocation
class LocationManager: NSObject, CLLocationManagerDelegate {
/// Location manager to request authorization and location updates.
let manager = CLLocationManager()
/// Flag indicating whether the manager is requesting the user's location.
var isRequestingLocation = false
var workoutLocation: CLLocation?
func requestLocation() {
guard !isRequestingLocation else {
manager.stopUpdatingLocation()
isRequestingLocation = false
return
}
let authorizationStatus = CLLocationManager.authorizationStatus()
switch authorizationStatus {
case .notDetermined:
isRequestingLocation = true
manager.requestWhenInUseAuthorization()
case .authorizedWhenInUse:
isRequestingLocation = true
manager.requestLocation()
case .denied:
print("Location Authorization Denied") …Run Code Online (Sandbox Code Playgroud) Xcode 15 Beta 8 中的 #Preview 宏的使用方式是否发生了变化?该代码曾经工作正常,但现在不再编译,因为== PREVIEW UPDATE ERROR: CompileDylibError: Failed to build WatchRecoveryWidget.swift Compiling failed: cannot convert value of type 'WatchRecoveryScoreTimeLineEntry' to closure result type 'any View'
#Preview(as: WidgetFamily.accessoryRectangular) {
WatchRecoveryScoreWidget()
} timeline: {
WatchRecoveryScoreTimeLineEntry(date: Date(), recoveryScore: 75, subscriptionIsActive: true)
}
Run Code Online (Sandbox Code Playgroud) iOS 15 引入了“.refreshable”视图修饰符,但我见过的大多数示例都使用List. 我想在一个不使用列表而仅VStack使用Text如下视图的应用程序中实现拉动刷新功能。我该如何实现这一点,以便下拉刷新将刷新我的数据?
import SwiftUI
struct ContentView: View {
@State var songName = "Song"
@State var artistName = "Artist"
var body: some View {
VStack {
Text(songName)
Text(artistName)
}
.refreshable {
reloadData()
}
}
private func reloadData() {
songName = "Let it Be"
artistName = "The Beatles"
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Run Code Online (Sandbox Code Playgroud) ios ×8
swift ×7
swiftui ×3
xcode ×3
apple-watch ×2
healthkit ×2
xcode15 ×2
ios15 ×1
refreshable ×1
spotify ×1
swift-macro ×1
watchkit ×1
watchos ×1
watchos-4 ×1
widgetkit ×1