标签: watchos-2

WatchOS2心率

嗨其他开发者,

我们不得不等待它,但它终于来了......或者不是吗?

关于Watch OS 2 beta中新的心率选项的常见问题.我的跑步应用程序可以每秒钟从心率监测中受益,还是我们必须使用仅每10分钟刷新一次的健康套件版本(左右?).

ios healthkit watchos-2

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

WCSession 和 Today 小部件

我有一个带有今天扩展的应用程序和一个手表应用程序。从主应用程序 WCSession 工作正常,数据传输到手表并正确接收,但是当我尝试通过今天小部件中的 WCSession 发送或接收数据时,会话的属性pairedwatchAppInstalled会话设置为 false,因此调用transferUserInfo:什么也不做,session:didReceiveUserInfo:永远不会叫。

我知道我可以使用打开应用程序openURL然后发送新数据,但我想在不离开通知中心的情况下这样做。有谁知道这个问题的一个很好的解决方法?

ios ios8-today-widget watchkit today-extension watchos-2

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

手表OS 2上的NSURL请求

我刚刚将Xcode更新到最新的手表测试版,我之前正在研究的项目有错误,而这些错误并不存在.

这是我的代码:

NSString *urlToSet = [[NSString alloc] initWithFormat:@"http://www.example.com/"];
self.responseData = [NSMutableData data];
NSURLRequest *request = [NSURLRequest requestWithURL:
                         [NSURL URLWithString:urlToSet]];
(void)[[NSURLConnection alloc] initWithRequest:request delegate:self];
Run Code Online (Sandbox Code Playgroud)

错误发生在最后一行,它说:

'initWithRequest:delegate:' is unavailable: not available on watchOS
Run Code Online (Sandbox Code Playgroud)

xcode objective-c nsurlconnection watchkit watchos-2

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

WatchKit didReceiveApplicationContext没有被调用

不敢didReceiveApplicationContext打电话。有任何想法吗?

InterfaceController

import WatchKit
import Foundation
import WatchConnectivity

class InterfaceController: WKInterfaceController, WCSessionDelegate {

    @IBOutlet var colorLabel: WKInterfaceLabel!

    private let session: WCSession? = WCSession.isSupported() ? WCSession.defaultSession() : nil

    override init() {
        super.init()
        session?.delegate = self
        session?.activateSession()
    }

    override func awakeWithContext(context: AnyObject?) {
        super.awakeWithContext(context)
    }

    func session(session: WCSession, didReceiveApplicationContext applicationContext: [String : AnyObject]){
        let colors : String = applicationContext["color"] as! String
        colorLabel.setText(colors)
        NSLog("session did receive application context")
    }

}
Run Code Online (Sandbox Code Playgroud)

我一直在跟随本教程:http : //www.kristinathai.com/watchos-2-how-to-communicate-between-devices-using-watch-connectivity/

NSLogcolorLabel …

swift watchkit xcode7 watchos-2

2
推荐指数
2
解决办法
2721
查看次数

有没有办法直接从iPhone应用程序更新复杂功能?

如果可能的话,我想让用户能够完全绕过手表应用程序.

我已经尝试在我的ViewController上导入ClockKit来创建一个实例 CLKComplicationServer.我得到"没有这样的模块"错误.

有没有办法直接与iOS应用程序的复杂功能进行通信?

apple-watch watchos-2 apple-watch-complication

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

如何在WatchOS 2和Swift中将变量从一个View Controller传递到另一个View Controller

我在尝试从一个View Controller到下一个View Controller获取几个变量时遇到很多问题。我该怎么做呢?这是我的下面的代码。这就是我希望能够发送变量视图控制器RedScoreW,并BlueScoreW到下一个窗口。我在问如何使用SWIFT语言(尤其是WATCHOS应用程序)执行此操作。

class InterfaceController2: WKInterfaceController {

    var RedScoreW = 0
    var BlueScoreW = 0


    @IBOutlet var WatchRedScoreLabel: WKInterfaceLabel!
    @IBOutlet var WatchBlueScoreLabel: WKInterfaceLabel!

    @IBAction func RedScorePlus() {
        if RedScoreW == 999 {
            RedScoreW = 0
            WatchRedScoreLabel.setText("0")
        }else {
            RedScoreW += 1
            WatchRedScoreLabel.setText(String(RedScoreW))
        }
    }
    @IBAction func RedScoreMinus() {
        if RedScoreW == 0 {
            RedScoreW = 999
            WatchRedScoreLabel.setText("999")
        }
        else {
        RedScoreW -= 1
        WatchRedScoreLabel.setText(String(RedScoreW))
        }
    }

    @IBAction func BlueScorePlus() {
        if BlueScoreW == 999 {
            BlueScoreW …
Run Code Online (Sandbox Code Playgroud)

variables viewcontroller watchapp swift2 watchos-2

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

HKAnchoredObjectQuery结果处理程序在初始结果后不会触发

我们的健身应用程序使用三个锚定对象查询来传输心率,活跃卡路里和距离; 直到几个星期前,当我们开始优化应用程序的其余性能时,它才能正常工作,以便更快地响应并查询过去锻炼的样本.我们相信我们已经将查询恢复到以前的状态,并且我们有非常相似的代码但是用Swift编写的单独的健身应用工作正常,但是这些HKAnchoredObjectQuerys在处理初始结果后不会返回更多结果(是的,锻炼课程是活跃的).我们有点难过.任何人都可以看看,并建议我们可能出错的地方?

谢谢!

以下是心率查询的示例:

- (HKQuery*) createHeartRateStreamingQuery: (NSDate *) workoutStartDate {  
    NSPredicate * predicate = [HKQuery predicateForSamplesWithStartDate:workoutStartDate endDate:nil options:HKQueryOptionNone];  

    HKQueryAnchor *anchor = HKAnchoredObjectQueryNoAnchor;  
    if (_HRAnchor) {  
        anchor = _HRAnchor;  
    }  

    HKQuantityType * quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate];  

    HKAnchoredObjectQuery *query =  
    [[HKAnchoredObjectQuery alloc]  
     initWithType:quantityType  
     predicate:predicate  
     anchor:anchor  
     limit:HKObjectQueryNoLimit  
     resultsHandler:^(HKAnchoredObjectQuery * query,  
                      NSArray<HKSample *> * sampleObjects,  
                      NSArray<HKDeletedObject *> * deletedObjects,  
                      HKQueryAnchor * newAnchor,  
                      NSError * error) {  

             if (error) {  
                 NSLog(@"*** %s An error occured while performing the heartrate anchored object query. %@ ***", …
Run Code Online (Sandbox Code Playgroud)

healthkit watchos-2

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

两件式图像并发症

我想显示一个多色复杂功能图标,类似于默认的计时器应用程序图标:

在此处输入图片说明

这是我用多色显示图标的代码:

CLKComplicationTemplateModularSmallStackImage* template=[[CLKComplicationTemplateModularSmallStackImage alloc]init];

template.line1ImageProvider=[CLKImageProvider imageProviderWithOnePieceImage:[UIImage imageNamed:@"Complication/Modular"] 
    twoPieceImageBackground:[UIImage imageNamed:@"ComplicationForeground/Modular"] 
    twoPieceImageForeground:[UIImage imageNamed:@"ComplicationBackgroud/Modular"]];

entry = [CLKComplicationTimelineEntry entryWithDate:[NSDate date]
                                           complicationTemplate:template];
Run Code Online (Sandbox Code Playgroud)

两幅图像都有清晰的背景。如何使用 whiteColor 为中心图像着色,并使用另一种颜色为外部图像着色?

xcode objective-c watchkit watchos-2 apple-watch-complication

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

WatchKit应用程序在运行背景后丢失数据 - Swift

我正在使用(watchOS 2)applicationContext方法将我的iPhone中的字典传递给手表.

在iPhone应用程序内:

func giveMeInfo(){
    var lastStringUsed = porkee288.storyPoints.last!
    do {
        let resultDict = ["dict": myDict]
        try WCSession.defaultSession().updateApplicationContext(resultDict)
    }  
    catch {
        print("Something wrong happened")
    }
}
Run Code Online (Sandbox Code Playgroud)

在手表应用内:

func session(session: WCSession, didReceiveApplicationContext applicationContext: [String : AnyObject]) {

    dispatch_async(dispatch_get_main_queue()) { () -> Void in

        if let retrievedDict = applicationContext["dict"] as? [String : String] {

                self.dictInsideWatch = retrievedDict     
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

该数据由提取tableviewwatchKit很好,但是,每个应用程序进行到背景时,数据自动丢失,这很奇怪,因为在iPhone应用字典有一些持久性(至少直到变得悬浮).

您建议如何解决此问题并防止数据消失?

ios swift apple-watch watchkit watchos-2

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

观看应用以错误clientIdentifier开头的interfaceControllerID找不到

我在watchos2上有一个smartwatch应用程序。该应用程序始终可以运行,但是现在启动时,我立即收到此错误:

Lop_WatchKit_Extension[17535:7854201] *********** ERROR -[SPRemoteInterface _interfaceControllerClientIDForControllerID:] clientIdentifier for interfaceControllerID:447E0002 not found
Run Code Online (Sandbox Code Playgroud)

我在这里找到了一些有关stackoverflow的主题,但没有任何解决方案。

objective-c ios watchos-2

2
推荐指数
2
解决办法
1310
查看次数