2

Hi every one i have to update instantly from my parent app (iPhone App) and Show the value in the watch App. I have to reload the value in the watch screen when ever the apps values get updated. I have to update from the app and show it in its extension app. enter image description here

if change the location in the iPhone app. Automatically the values should be changed in watch App. I'm using App Group and NSUserDefault to share values between these apps.Now i can access values from the watch App but its not get updated automatically. Thanks in advance

4

1 回答 1

2

You can set a timer and change the contents of labels.

In WatchKit (WKInterfaceLabel), setting label's contents is very easy. Just use the following code in order to set a new text for labels:

Swift:

label1.setText(temperature)

Objective-C:

[label1 setText:temperature];

Also you can do the same with pictures, charts etc. Just insert the code said before in a function, and call that function each time the timer finishes its interval time.

It's better to set short intervals for timer. Less interval means refreshing faster but more internet usage and battery drain, and longer intervals means refreshing not fast as previous way, but less internet usage and more battery saving.

You can change the interval in run-time by battery percentage. If it is - for example, less than 20% - you can set longer intervals, and when it is more than 20%, set shorter ones. You can only find Apple Watch battery percentage in watchOS 2, but in both versions you can get iPhone battery percentage by the following code:

Swift:

var x = UIDevice.currentDevice().batteryLevel

Objective-C:

int x = [UIDevice currentDevice].batteryLevel;

NOTE: Short intervals are from 10ms to 200ms, and long ones are from 200ms to 1s. (ms = Milliseconds = 0.001 seconds)

NOTE: You can call the initialization method of the view in timer intervals.

If you want to update view manually, just make a button, and set labels and charts' data (by the code given before) or call the view init method.

于 2015-06-29T16:16:59.417 回答