Ios 苹果手表-更新背景一瞥

Ios 苹果手表-更新背景一瞥,ios,background,apple-watch,Ios,Background,Apple Watch,我正在开发一个AppleWatch应用程序,我想知道是否有可能更新背景中的一瞥。当用户打开浏览时,我想让浏览以中间方式进行更新,而不是等到浏览从服务接收到更新的信息并显示出来 目前,我正在使用此功能更新浏览,但这将显示信息更新不在中间 - (void)awakeWithContext:(id)context // This function can't spend too much time processing the data otherwise we will se a black bac

我正在开发一个AppleWatch应用程序,我想知道是否有可能更新背景中的一瞥。当用户打开浏览时,我想让浏览以中间方式进行更新,而不是等到浏览从服务接收到更新的信息并显示出来

目前,我正在使用此功能更新浏览,但这将显示信息更新不在中间

- (void)awakeWithContext:(id)context // This function can't spend too much time processing the data otherwise we will se a black background. Can't call the service here.
{
    //Configure the interface using the cached info. 
    [super awakeWithContext:context];
}


- (void)willActivate 
{
    //Configure the interface using the service
    [super willActivate];
}
有什么想法吗


提前感谢。

您可以在iOS应用程序中安排后台提取,提取后,将数据保存到共享组容器中。
然后,在glance控制器的awakeWithContext方法中,您可以从该共享组容器中获取数据。它应该足够快

第一次出现您的一瞥时,您可以在
init
中向用户提供一条通用的欢迎信息。然后,在
中将激活
(或者,我想,
唤醒上下文:
)填充控件并启动计时器,定期获取更新内容以供浏览

正如Ivp所建议的,您应该将更新的数据存储在一个共享容器中。(看一看)

如果你知道你的iPhone应用程序将在你的一瞥启动之前启动,你可以跳过一般的欢迎信息,仅仅依靠它在共享容器中播种数据

- (instancetype)init {
    self = [super init];

    if (self) {
        if (isFirstLaunch) {
            self.displayInfo = [self createWelcomeInfo];
        }
    }

    return self;
}

- (void)willActivate {
    [super willActivate];

    // refreshUI will check for new data, request more for next time,
    // and then configure the display labels with the new data.
    [self refreshUI]; 

    // Setup a timer to refresh the glance based on new trends provided by the phone app.
    // NOTE: This timer is never invalidated because didDeactivate seems to never be called.
    //       If, by chance, willActivate is called more than once, we may end up with multiple repeating timers.
    self.refreshTimer = [NSTimer scheduledTimerWithTimeInterval:kTimeIntervalRefresh
                                                         target:self
                                                       selector:@selector(refreshUI)
                                                       userInfo:nil
                                                        repeats:YES];
}

- (void)refreshUI {
    if (! isFirstLaunch ) {
        if (self.nextDisplayInfo) {
            self.displayInfo = self.nextDisplayInfo;
        }

        // requestMoreInfo will populate self.nextDisplayInfo asynchronously,
        // so it's ready for the next time you are in refreshUI
        [self requestMoreInfo];
    }

    [self configureLabels:self.displayInfo];

    // Setup for when the user taps the glance
    [self updateUserActivity:@"com.example.AppName" userInfo:@{@"data": self.displayInfo} webpageURL:nil];    
}
这里是我上面描述的一个示例,尽管它没有显示共享容器中的数据存储

- (instancetype)init {
    self = [super init];

    if (self) {
        if (isFirstLaunch) {
            self.displayInfo = [self createWelcomeInfo];
        }
    }

    return self;
}

- (void)willActivate {
    [super willActivate];

    // refreshUI will check for new data, request more for next time,
    // and then configure the display labels with the new data.
    [self refreshUI]; 

    // Setup a timer to refresh the glance based on new trends provided by the phone app.
    // NOTE: This timer is never invalidated because didDeactivate seems to never be called.
    //       If, by chance, willActivate is called more than once, we may end up with multiple repeating timers.
    self.refreshTimer = [NSTimer scheduledTimerWithTimeInterval:kTimeIntervalRefresh
                                                         target:self
                                                       selector:@selector(refreshUI)
                                                       userInfo:nil
                                                        repeats:YES];
}

- (void)refreshUI {
    if (! isFirstLaunch ) {
        if (self.nextDisplayInfo) {
            self.displayInfo = self.nextDisplayInfo;
        }

        // requestMoreInfo will populate self.nextDisplayInfo asynchronously,
        // so it's ready for the next time you are in refreshUI
        [self requestMoreInfo];
    }

    [self configureLabels:self.displayInfo];

    // Setup for when the user taps the glance
    [self updateUserActivity:@"com.example.AppName" userInfo:@{@"data": self.displayInfo} webpageURL:nil];    
}