2015-01-15 29 views
2

我正在开发AppleWatch应用程序,我想知道是否有可能更新背景中的一瞥。当用户打开浏览器时,我想让INMEDIATLY更新浏览器,而不是等到浏览器从服务器收到更新的信息并显示出来。苹果手表 - 更新一眼背景

目前我使用此功能来更新一目了然,但这将显示信息更新不中。

- (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]; 
} 

任何想法?

在此先感谢。

回答

1

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

-1

第一次出现您的目光时,您可以在init中为用户提供一般性欢迎信息。然后,在willActivate(或,我想,awakeWithContext:)填充您的控件并启动计时器以定期抓取更新内容。

正如Ivp建议的那样,您应该将更新的数据存储在共享容器中。 (看看NSUserDefaults:initWithSuiteName:

如果您知道您的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];  
}