标签: watchkit

WatchKit 如何使用标识符执行特定的转场

我有一个按钮,它已经连接到 InterfaceBuilder 中以显示一个模态界面控制器。在某些情况下,我想以编程方式触发此转换,但我找不到在 Watchkit 中执行相同转场的方法。我知道您可以在 iphone/iOS 中执行此操作,但到目前为止我无法在 Watchkit 中找到它。

segue apple-watch watchkit

1
推荐指数
1
解决办法
1610
查看次数

Watchkit 扩展无法从 iCloud 读取

我正在寻找 watchkit 扩展来从 iCloud 文档存储中读取文件。我从 iOS 应用程序编写了该文件,该应用程序也可以读取它。我正在利用共享类,因此代码是相同的。问题是在手表上,云容器的 URL 返回 nil。

static func readFromFile(fileName:String) -> String?
{
    let fileManager = FileManager.default
    var cloudURL = fileManager.url(forUbiquityContainerIdentifier: nil)

    cloudURL = cloudURL?.appendingPathComponent("Documents/\(fileName)")

    do
    {
        return try String(contentsOf: cloudURL!)
    } catch {
        print (error)
        return nil
    }
Run Code Online (Sandbox Code Playgroud)

在上面的例子中,cloudURL在手表上是nil,但在手机上不是。为此,forUbiquityContainerIdentifier我检查了手表和手机使用相同的标识符。我还尝试直接输入名称,而不是使用 nil 并让它从权利中获取它。容器的格式:

iCloud.com.company.app
Run Code Online (Sandbox Code Playgroud)

据我了解,Watch OS 3 应该能够使用 iCloud。

更新:

我打印出来let token = fileManager.ubiquityIdentityToken并得到以下内容:

WatchKit Extension[390:687462] [default] [ERROR] 获取 ubiquityIdentityToken 时出错:Error Domain=NSCocoaErrorDomain Code=4099 “与名为 com.apple.bird.token 的服务的连接已失效。” UserInfo={NSDebugDescription=与名为 com.apple.bird.token 的服务的连接已失效。}

icloud swift watchkit

1
推荐指数
1
解决办法
469
查看次数

watchOS 如何找到主故事板文件?

出于功能标志的原因,我想要两个故事板文件。一次只会使用一个,但我想要两个文件用于在构建之间来回切换。但是,我找不到 watchOS 确定要加载哪个故事板文件的位置。

iOS 在 Info.plist 中有一个键UIMainStoryboardFile。但watchOS 没有这样的密钥

当我在“常规”“信息”中检查当前的 Watch Extension 和 Watch App 目标时部分中检查当前的 Watch Extension 和 Watch App 目标时,我发现没有提及故事板文件。

请注意,watchOS确实WKExtensionDelegateClassNameInfo.plist 的密钥,这也将满足我的功能标记目的。但是,我的代码中没有WKExtensionDelegate指定特定的故事板。

在 Xcode 中,当我在文件检查器右窗格中查看当前的手表故事板文件时,我没有看到初始故事板的特殊指示符标记。以防万一它被列在那里。

watchOS 的应用程序编程指南也没有解释如何建立连接。

有任何想法吗?

info.plist watchkit

1
推荐指数
1
解决办法
1205
查看次数

watchOS 不能 sendMessage() 一个结构

我在我的 iOS 应用程序和它的 Apple Watch 扩展中都声明了这个结构

struct nonIndexStruct {
    let name: [String]
    let message: [String]
}
Run Code Online (Sandbox Code Playgroud)

我创建了一个这样的对象

let nIS = nonIndexStruct(name: sortedNameArray.map({ ($0 ).name }), message: sortedNameArray.map({ ($0 ).name }))

为了将它传递给我的 Apple Watch 扩展,我将对象放入一个 dict

let chatsMasterDict:[String: Any] = ["chatsMaster": nIS]

打印这个工作得很好,所有数据都在这个对象中可用。要发送它,我打电话

session.sendMessage(chatsMasterDict, replyHandler: nil, errorHandler: nil)

现在的问题是 Apple Watch 方面什么也没有。errorHandler 仅在未打开 Apple Watch 应用程序时打印一些内容。(关于手表应用程序未打开)

Apple Watch 上的接收方法如下所示,它打印接收到的所有内容 - 除了上面显示的情况外,该方法根本不会被调用。

func session(_ session: WCSession, didReceiveMessage message: [String : Any]) {
    print("didReceive")
    print (message)

    if let val = message["chatsMaster"]{
        print("chatsMaster came") …
Run Code Online (Sandbox Code Playgroud)

ios swift watchkit watchos

1
推荐指数
1
解决办法
433
查看次数

WCSession:使用 transferUserInfo 或 sendMessage 的最佳方式?

我目前正在使用 transferUserInfo() 以字典数组的形式发送用户列表。

我开始认为我真的没有利用 UserInfo 传输提供给我的 FIFO 行为。

所以我开始考虑是否可以使用 sendMessage() 发送我的数据。

它对每种后台传输方法可以包含的数据量有什么不同吗?

或者使用 transferUserInfo() 而不使用其 FIFO 行为是否可以?

ios swift apple-watch watchkit wcsession

1
推荐指数
1
解决办法
525
查看次数

HKWorkoutSessionDelegate:workoutSession(_:didGenerate:) 暂停检测问题

我正在为 Apple Watch 构建跑步锻炼项目,但在实现“自动暂停”功能时遇到问题。委托HKWorkoutSessionDelegate : workoutSession(_:didGenerate:)应该获取系统生成的一些暂停事件。

我遇到的问题是我的会话永远不会启动:暂停事件立即发送给委托。

我的代码:

func workoutSession(_ workoutSession: HKWorkoutSession, didGenerate event: HKWorkoutEvent) {
            // press 2 buttons
            if(event.type == HKWorkoutEventType.pauseOrResumeRequest) {
                print("Detected Press")
                if workoutData.isPaused == false {
                    pauseWorkout()
                }
                else {
                    resumeWorkout()
                }
            }

            // Auto-pause
            if event.type == HKWorkoutEventType.motionPaused && workoutSettings.autoPause {
                print("Auto Pause")
                pauseWorkout()
            }
            if event.type == HKWorkoutEventType.motionResumed && workoutSettings.autoPause {
                print("Auto Resume")
                resumeWorkout()
            }
        }
Run Code Online (Sandbox Code Playgroud)

问题出现在“//自动暂停”部分。我错过了什么吗?

appdelegate swift healthkit watchkit pause

1
推荐指数
1
解决办法
662
查看次数

使用 NavigationLink() 时出现“类型 '[view]' 无法符合 'View'”错误

我有一个使用 SwiftUI 构建的简单 Apple Watch 应用程序。我正在尝试添加一个按钮以从“我”转到“ContentViewSettingsView使用”NavigationLink

\n
struct ContentView: View {\n    \n    @EnvironmentObject var settings: SettingsObject\n    @EnvironmentObject var chilly: ChillyObject\n    \n    var body: some View {\n        ZStack{\n            VStack{\n\n                Text(chilly.message)\n                    .foregroundColor(chilly.textColor)\n                    .font(.largeTitle)\n                    .fontWeight(.heavy)\n                    .multilineTextAlignment(.center).fixedSize(horizontal: false, vertical: true)\n                    .padding(.top, 9.0)\n                            \n                Text(chilly.emoji)\n                    .font(.largeTitle).foregroundColor(Color.black)\n                    .multilineTextAlignment(.center)\n                    .padding(.bottom, -20.0)\n                \n                NavigationLink(destination: SettingsView) {\n                    Text("\xe2\x9a\x99\xef\xb8\x8f Settings")\n                        .font(.body)\n                        .fontWeight(.semibold)\n                }\n                .frame(width: 120.0)\n\n            }\n        }\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n
struct SettingsView: View {\n    \n    @EnvironmentObject var settings: SettingsObject\n            \n    var body: some View {\n        ZStack …
Run Code Online (Sandbox Code Playgroud)

swift watchkit watchos swiftui

1
推荐指数
1
解决办法
2501
查看次数

watchkit,iOS在手表和iphone之间发送数据

我想在手表中创建一个按钮,同时点击手表启动一个进程到我的ios应用程序.如何在两台设备之间发送数据

-(void)viewWillAppear:(BOOL)animated

{
 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(sayHello:) name: @"sayHelloNotification" object: nil];

}
Run Code Online (Sandbox Code Playgroud)

 [[NSNotificationCenter defaultCenter] postNotificationName: @"sayHelloNotification" object: nil];
Run Code Online (Sandbox Code Playgroud)

在我的按钮手表,但它不起作用

objective-c nsnotifications nsnotificationcenter ios watchkit

0
推荐指数
1
解决办法
1万
查看次数

WatchKit WKInterfaceGroup可以成为Button吗?

(使用iOS8.3,Xcode6.3,OSX10.10.3)

嗨,我想知道WatchKit WKInterfaceGroup是否可以成为Button?

在我的watchkit-application中,我想最大化特定动作的触摸表面.

我知道可以在一个集合中放置一个或多个按钮(与标签,图像等其他东西相邻).有这样一个带有小项目的WKInterfaceGroup(称为组) - 我想放置几个按钮,所有按钮都填充了组容器之间的空白区域.

但是通过在组中放置几个​​彼此靠近的按钮,即使它们都引用了相同的动作,我也意识到用组的用户手指触摸两个按钮不会使我达到所需的表面增加.

问题是,用户手指一次触摸多个按钮,甚至很难,我给了组中的所有按钮,如上所述,后面的动作完全相同,动作不会被解雇.

如果可能,解决方案可能是将整个组定义为按钮.怎么会这样?(...也许可访问性特征可以帮助??或其他...... ???).或者你可以以某种方式将按钮叠加到一个组???

任何想法赞赏!

ios watchkit wkinterfacegroup

0
推荐指数
1
解决办法
445
查看次数

Apple Watch核心位置错误***断言失败 - [CLLocationManager requestLocation]

我尝试使用coreLocation在Apple Watch上获取用户当前位置.每当我运行时-[CLLocationManager requestLocation],应用程序退出并发出以下错误.

2016-02-07 16:38:39.392 Placescope Apple Watch Extension[6255:1471552]     *** Assertion failure in -[CLLocationManager requestLocation], /BuildRoot/Library/Caches/com.apple.xbs/Sources/CoreLocationFramework_Sim/CoreLocation-1861.3.25.31/Framework/CoreLocation/CLLocationManager.m:816
2016-02-07 16:38:39.395 Placescope Apple Watch Extension[6255:1471552] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Delegate must respond to locationManager:didUpdateLocations:'
*** First throw call stack:
(
    0   CoreFoundation                      0x00bb9fc4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x00671df4 objc_exception_throw + 50
    2   CoreFoundation                      0x00bb9e5a +[NSException raise:format:arguments:] + 138
    3   Foundation                          0x0029a008 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 118
    4   CoreLocation                        0x0013a4f9 CLClientGetCapabilities + 12683
    5   Placescope Apple Watch …

objective-c core-location ios watchkit

0
推荐指数
1
解决办法
1311
查看次数