Apple Watch - 仅在手机上的应用处于活动状态时获取数据 [英] Apple Watch - only getting data if app on phone is active

查看:107
本文介绍了Apple Watch - 仅在手机上的应用处于活动状态时获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用模拟器开发并部署了Apple Watch Extension App。它已经被批准,现在可以在应用程序商店购买,所以Apple很高兴!

I have developed and deployed our Apple Watch Extension App using the simulator. It's been approved and is available right now on the app store, so Apple are happy!

今天我能够亲身体验手表并发现一个真实的问题 - 我只能与手表互动,如果我手机上的应用程序不仅仅是打开,而且还是活动的......从而击败了对象。

Today I was able to get my hands on a physical watch and have discovered a real problem - I can only interact watch-phone, if the app on my phone is not just open, but also active...thus defeating the object.

我正在实施手机应用程序的 appDelegate 中的以下方法作为代理获取我的实时数据并将其返回手表。

I am implementing the below method in the appDelegate of the phone app as a proxy to get my live data and return it to the watch.

我基本上将请求传递给 appDelegate - 我检查userInfo应该返回哪些数据,然后手机应用程序执行业务并返回包含userInfo字典要解析的手表数据:

I basically pass in a request to the appDelegate - I check the userInfo for which data should be returned, then the phone app does the business and returns a userInfo dictionary containing data for the watch to parse:

-(void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply {

if ([userInfo objectForKey:@"GetWatchData"]) {

    [TPWatchData configureWatchData:^(BOOL success) {

        if (success) {

            reply([TPWatchData watchData]);

        } else {

            reply(@{@"FAIL":@"AppDelegate"});

        }


    }];

}

}

我正在打电话它在手表上使用这种方法在手表扩展(只是我调用的一个例子):

I am calling it in the watch using this approach on the watch extension (just one example of the calls I make):

    [TPWPlanList openParentApplication:@{@"GetWatchData":@1} reply:^(NSDictionary *replyInfo, NSError *error) {

    if ([replyInfo objectForKey:@"Overview"]) {

        if (error.code == 0) {

            if ([replyInfo objectForKey:@"FAIL"]) {

                // Something failed

            } else {

                self.dic_overview = [replyInfo objectForKey:@"Overview"];

                //[self reloadPlanListTable];

            }

        } else {

            // Something failed

        }

    }

}];

如前所述,这在模拟器中完美运行,实际上在物理手表上完美运行 - 但仅限于如果我在手机上打开主应用程序并激活。应用程序在后台或手机显示屏休眠的那一刻,使用上述方法无法传递数据。

As already stated, this worked perfectly in the simulator and actually works perfectly on the physical watch - but ONLY if I have the main app open on the phone and active. The minute the app is in the background or the phone display sleeps, no data is passed using the above method.

有什么想法吗?我显然做错了什么,但是我已经设法在整个事情发生之前,在真正的设备上,在它被咬了之前。

Any thoughts? I am clearly doing something wrong, but I've managed to get to the point of the entire thing being live and on real devices, before it's bitten me.

非常感谢!

推荐答案

如果您的 openParentApplication:reply:方法仅适用于主机iOS应用程序处于活动状态,我几乎可以保证您的iOS应用程序在它有机会回复之前在后台被杀死。

If your openParentApplication:reply: method only works when the host iOS app is active, I can pretty much guarantee that your iOS app is being killed in the background before it has a chance to reply.

解决方案是让应用程序尽快响应请求,然后完成正常任务。在开发人员论坛中有一个关于此的说明: https://devforums.apple.com/thread / 264473?tstart = 0

The solution is to have the app respond to the request as quickly as possible, then complete your normal task. There's a note about this in the developer forums: https://devforums.apple.com/thread/264473?tstart=0

我还撰写了一篇博文,详细介绍了我在论坛中添加说明之前使用的方法: http://www.fiveminutewatchkit.com/blog/ 2015/3/11 / one-strange-to-fix-openparentapplicationreply

I've also written a blog post detailing the methods I used before the note was added in the forums: http://www.fiveminutewatchkit.com/blog/2015/3/11/one-weird-trick-to-fix-openparentapplicationreply

这篇关于Apple Watch - 仅在手机上的应用处于活动状态时获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆