-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathPBWatch+Sports.h
503 lines (456 loc) · 18.5 KB
/
PBWatch+Sports.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
//
// PBWatch+Sports.h
// PebbleKit
//
// Created by Martijn The on 2/7/13.
// Copyright (c) 2013 Pebble Technology. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <PebbleKit-Static/PBDefines.h>
#import <PebbleKit-Static/PBWatch.h>
NS_ASSUME_NONNULL_BEGIN
@class UIImage;
/**
* The UUID of the Sports watch app.
*/
PB_EXTERN NSUUID *PBSportsUUID;
// The documentation for these keys is in -[PBWatch sportsAppUpdate:onSent:].
PB_EXTERN NSNumber *PBSportsTimeKey;
PB_EXTERN NSNumber *PBSportsDistanceKey;
PB_EXTERN NSNumber *PBSportsDataKey;
PB_EXTERN NSNumber *PBSportsActivityStateKey;
PB_EXTERN NSNumber *PBSportsIsPaceKey;
PB_EXTERN NSNumber *PBSportsHeartBPMKey;
PB_EXTERN NSNumber *PBSportsCustomLabelKey;
PB_EXTERN NSNumber *PBSportsCustomValueKey;
/**
* The state of the Sports activity.
*
* @see -[PBWatch sportsAppAddReceiveUpdateHandler:]
*/
typedef NS_ENUM(uint8_t, SportsAppActivityState) {
SportsAppActivityStateInit = 0x00,
SportsAppActivityStateRunning = 0x01,
SportsAppActivityStatePaused = 0x02,
SportsAppActivityStateEnd = 0x03,
};
/**
* The unit system available for the Sports app.
*
* @see -[PBWatch(Sports) sportsAppSetUnitSystem:onSent:]
*/
typedef NS_ENUM(NSInteger, PBUnitSystem) {
/// The metric system. Use kilometers, kilometers per hour and minutes per
/// kilometer.
PBUnitSystemMetric,
/// The imperial system. Use miles, miles per hour and minutes per mile.
PBUnitSystemImperial,
};
/**
* Packages a UI update of the sports app.
*
* This container class includes new values of time, distance, pace or
* speed, heart rate, and a custom label/value. To send the values to the
* watch use -[PBSportsUpdate updateWatch:completion:].
*
* The class is mutable, so consumers can update the values and send the same
* instance again. Modifying the values of this class will not send the values.
* The consumer needs to invoke -[PBSportsUpdate updateWatch:completion:] every
* time the UI needs to be updated.
*/
PB_EXTERN_CLASS @interface PBSportsUpdate : NSObject
/**
* The current time in seconds.
*
* The possible range is currently limited from -35999 to 35999,
* inclusive (±9h 59min 59sec). Values larger or smaller than the limits will
* be transformed into the maximum or minimum, respectively.
*
* It will be presented as a duration string in the UI. Hours, minutes and
* seconds will be separated by colons. The hours value will only appear if
* the value is more than 1 hour. The decimal part will be discarded for the
* presentation.
*/
@property (nonatomic) NSTimeInterval time;
/**
* The current distance in kilometers or miles.
*
* The possible range is currently limited from -99.9 to 99.9, inclusive. Values
* larger or smaller than the limits will be transformed into the maximum or
* minimum, respectively.
*
* It will be presented as a decimal number in the UI. The decimal part will be
* rounded to one digit.
*
* The unit of distance is dependent on the current unit setting.
*
* @see -[PBWatch sportsAppSetMetric:onSent:]
*/
@property (nonatomic) float distance;
/**
* The current pace in seconds per kilometer or seconds per mile.
*
* The possible range is currently limited from -3599 to 3599,
* inclusive (±59min 59sec). Values larger or smaller than the limits will be
* transformed into the maximum or minimum, respectively.
*
* It will be presented as a duration string in the UI. Minutes and seconds will
* be separated by colons. The decimal part will be discarded for the
* presentation.
*
* Currently pace and speed cannot be presented at the same time. Setting speed
* will discard the value set through pace.
*/
@property (nonatomic) NSTimeInterval pace;
/**
* The current speed in kilometers per hour or miles per hour.
*
* The possible range is currently limited from -99.9 to 99.9, inclusive. Values
* larger or smaller than the limits will be transformed into the maximum or
* minimum, respectively.
*
* It will be presented as a decimal number in the UI. The decimal part will be
* rounded to one digit.
*
* Currently pace and speed cannot be presented at the same time. Setting pace
* will discard the value set through speed.
*/
@property (nonatomic) float speed;
/**
* The current heart rate in beats per minute.
*
* Currently there’s no way to stop sending heart rate values if one heart rate
* value was sent. The last value will be shown in the UI.
*
* If the heart rate has never been set before, this property will return zero.
*/
@property (nonatomic) uint8_t heartRate;
/**
* A custom label to show in the sports UI.
*
* The maximum number of characters is ~10, but this maximum is not enforced.
* The label will be sent in upper case to the watch.
*
* To be sent, both customLabel and customValue have to be set to non-nil values.
*/
@property (nonatomic, copy, nullable) NSString *customLabel;
/**
* A custom value to show in the sports UI.
*
* The maximum number of characters is ~8, but the maximum is not enforced.
*
* To be sent, both customValue and customLabel have to be set to non-nil values.
*/
@property (nonatomic, copy, nullable) NSString *customValue;
/**
* Creates an update dictionary from the receiver, that can be used with
* `-[PBWatch sportsAppUpdate:onSent:]`.
*
* You should prefer using `-[PBSportsUpdate updateWatch:completion:]`.
*
* @see -[PBWatch sportsAppUpdate:onSent:]
*/
@property (nonatomic, readonly) NSDictionary<NSNumber *, id> *appMessageDictionary;
/**
* Sends an update to the watch.
*
* The method tries to send the minimal set of changes since the last time the
* method was used, to try to minimize communication with the watch.
*
* @param watch The watch to send the update to.
* @param completion Block that will be called when the update either succeeds
* or fails.
*
* - `error`: `nil` if the operation was successful, or else an
* `NSError` with more information on why it failed.
*/
- (void)updateWatch:(PBWatch *)watch completion:(void (^__nullable)(NSError *__nullable error))completion;
/**
* Creates a formatted time string from a total seconds value, formatted as
* "h:mm:ss".
*
* For example, supplying the value 3930.0f seconds will return @"1:05:30".
*
* @param seconds The number of seconds from which to create the time string.
*
* @return Formatted time as "h:mm:ss"
*/
+ (NSString *)timeStringFromSeconds:(NSTimeInterval)seconds;
/**
* Creates a formatted decimal string with one decimal number.
*
* For example, supplying the value 13.42f will return @"13.4".
*
* @param decimal The decimal number to format as a string.
*
* @return The formatted decimal number.
*/
+ (NSString *)decimalStringFromFloat:(float)decimal;
@end
@interface PBWatch (Sports)
/**
* Queries the watch whether Sports Messages are supported.
*
* Must be called from the main thread.
*
* @param fetchedBlock The block that will be called when the inquiry has
* finished. The block will be called asynchronously
* on the queue that was originally used when calling this
* method.
*
* - `watch`: the recipient of the query.
* - `isSportsSupported`: `YES` if Sports API is supported,
* `NO` otherwise.
*/
- (void)sportsGetIsSupported:(void(^)(PBWatch *watch, BOOL isSportsSupported))fetchedBlock;
/**
* Send a command to launch the sports app on the watch that the receiver represents.
*
* Must be called from the main thread, and before sportsAppSetMetric:onSent:
* or sportsAppUpdate:onSent:.
*
* @param onSent The handler that will be called when the launch command has
* been sent or timed out (after 1.5 secs).
*
* - `watch`: the recipient of the command.
* - `error`: `nil` if the operation was successful, or else an
* `NSError` with more information on why it failed.
*/
- (void)sportsAppLaunch:(void(^ __nullable)(PBWatch *watch, NSError *__nullable error))onSent;
/**
* Send a command to kill the sports app on the watch that the receiver represents.
*
* Must be called from the main thread.
*
* @param onSent The handler that will be called when the kill command has been
* sent or timed out (after 1.5 secs).
*
* - `watch`: the recipient of the command.
* - `error`: nil if the operation was successful, or else an
* `NSError` with more information on why it failed.
*/
- (void)sportsAppKill:(void(^ __nullable)(PBWatch *watch, NSError *__nullable error))onSent;
/**
* Send a command to the sports app on the watch that the receiver represents,
* to set the preferred unit system.
*
* Must be called from the main thread.
*
* @param unitSystem `PBUnitSystemMetric` to request metric units or
* `PBUnitSystemImperial` to request imperial units.
* @param onSent The handler that will be called when the unit command has been
* sent or timed out (after 1.5 secs).
*
* - `watch`: the recipient of the command.
* - `error`: `nil` if the operation was successful, or else an
* `NSError` with more information on why it failed.
*/
- (void)sportsAppSetUnitSystem:(PBUnitSystem)unitSystem onSent:(void(^ __nullable)(PBWatch *watch, NSError *__nullable error))onSent;
/**
* Send a command to the sports app on the watch that the receiver represents,
* to set the state of the sports activity. Currently only
* `SportsAppActivityStateRunning` and `SportsAppActivityStatePaused` are
* supported.
*
* Must be called from the main thread.
*
* @param state The new sports activity state
* @param onSent The handler that will be called when the unit command has been
* sent or timed out (after 1.5 secs).
*
* - `watch`: the recipient of the command.
* - `error`: `nil` if the operation was successful, or else an
* `NSError` with more information on why it failed.
*/
- (void)sportsAppSetActivityState:(SportsAppActivityState)state onSent:(void(^ __nullable)(PBWatch *watch, NSError *__nullable error))onSent;
/**
* Sends the update to the sports app on the watch that the receiver represents.
*
* Must be called from the main thread.
*
* The valid keys and values for the dictionary are the following:
*
* - `PBSportsTimeKey`: the string representing the time. The value must be an
* `NSString`. The maximum number of characters is about 8.
* - `PBSportsDistanceKey`: the string representing the distance. The value must
* be an `NSString`. The maximum number of characters is about 5.
* - `PBSportsDataKey`: the string representing the pace or the speed. The value
* must be an `NSString`. The maximum number of characters is about 5.
* - `PBSportsActivityStateKey`: the state of the activity. The value must be an
* `NSNumber` created using +[NSNumber(stdint) pb_numberWithUint8:]. The value
* must be one of the values from the enum SportsAppActivityState.
* - `PBSportsIsPaceKey`: whether the value sent in `PBSportsDataKey` is the
* pace (use value 1) or the speed (use value 0). You don't need to
* continously send this value. The value must be an `NSNumber` created using
* +[NSNumber(stdin) pb_numberWithUint8:].
* - `PBSportsHeartBPMKey`: the current heart rate in beats per minute. The
* value must be an `NSNumber` created using
* +[NSNumber(stdin) pb_numberWithUint8:].
* - `PBSportsCustomLabelKey`: the string to show as a custom label. The value
* must be an `NSString`. The maximum number of characters is about 10. The
* string will be transformed into upper case before being sent to the watch.
* - `PBSportsCustomValueKey`: the string to show as a custom value. The value
* must be an `NSString`. The maximum number of characters is about 8.
*
* @param update The update to send.
* @param onSent The handler that will be called when the unit command has been
* sent or timed out (after 1.5 secs).
*
* - `watch`: the recipient of the command.
* - `error`: `nil` if the operation was successful, or else an
* `NSError` with more information on why it failed.
*/
- (void)sportsAppUpdate:(NSDictionary *)update onSent:(void(^__nullable)(PBWatch *watch, NSError *__nullable error))onSent;
/**
* Add a receive handler for incoming Sports updates that are send by the
* Sports watch application.
*
* Must be called from the main thread.
*
* @param onReceive The block that will be called every time a new update
* message arrives.
*
* - `watch`: The watch that has sent the update.
* - `state`: The new sports activity state as set by the
* watch.
*
* @return An opaque handle object representing the installed receive handler,
* that can be used in sportsAppRemoveUpdateHandler:.
*
* @see SportsAppActivityState
* @see sportsAppRemoveUpdateHandler:
*/
- (id)sportsAppAddReceiveUpdateHandler:(BOOL(^)(PBWatch *watch, SportsAppActivityState state))onReceive;
/**
* Removes a receive handler that was previously installed using
* sportsAppAddReceiveUpdateHandler:.
*
* Must be called from the main thread.
*
* @param opaqueHandle The handle object as returned by
* sportsAppAddReceiveUpdateHandler:
*
* @see sportsAppAddReceiveUpdateHandler:
*/
- (void)sportsAppRemoveUpdateHandler:(id)opaqueHandle;
/**
* Assigns a custom title and icon to the sports app on the watch.
*
* Must be called from the main thread.
*
* @discussion It is recommended to perform this as the first call after
* sportsGetIsSupported: to avoid changing the title
* and icon while it is being displayed in the menu as to avoid
* confusion.
*
* @param title The custom title (max. 20 bytes of UTF-8 string)
* @param icon The custom icon (max. 32x32 pixels, black/white only). This
* image cannot be `nil`.
* @param onSent The handler that will be called when the title and icon have
* been set or timed out.
*
* - `watch`: the recipient of the custom title and icon.
* - `error`: `nil` if the operation was successful, or else an
* `NSError` with more information on why it failed.
*/
- (void)sportsSetTitle:(NSString *)title icon:(UIImage *)icon onSent:(void(^ __nullable)(PBWatch *watch, NSError *__nullable error))onSent;
@end
@interface PBSportsUpdate (Deprecated)
/**
* General purpose data variable.
*
* @note The original property design is very broken and it has been deprecated
* in favor of both pace and speed. This value will act as pace from now
* on.
*
* The possible range is currently limited from -3599 to 3599,
* inclusive (±59min 59sec). Values larger or smaller than the limits will be
* transformed into the maximum or minimum, respectively.
*
* It will be presented as a duration string in the UI. Minutes and seconds will
* be separated by colons. The decimal part will be discarded for the
* presentation.
*
* Setting a value in either pace or speed will discard the value set through
* data.
*
* @see -[PBWatch sportsAppSetLabel:onSent:]
*
* @deprecated Prefer either `pace` or `speed`.
*/
@property (nonatomic) float data __attribute__((deprecated("Prefer either `pace` or `speed`")));
/**
* Creates a new `PBSportsUpdate` with the given time, distance and data.
*
* @param time The current time in seconds.
* @param distance The current distance in kilometers or miles.
* @param data General purpose data variable.
*
* @return A new `PBSportsUpdate` with the given time, distance and data.
*
* @deprecated Prefer -[PBSportsUpdate init] and filling the properties.
*/
+ (instancetype)updateWithTime:(NSTimeInterval)time distance:(float)distance data:(float)data __attribute__((deprecated("Prefer `[[PBSportsUpdate alloc] init]` and then filling the properties")));
/**
* Creates an update dictionary from the receiver that can be used with
* `-[PBWatch sportsAppUpdate:onSent:]`.
*
* @see -[PBWatch sportsAppUpdate:onSent:]
*
* @deprecated Prefer using -[PBSportsUpdate appMessageDictionary].
*/
- (NSDictionary *)dictionary __attribute__((deprecated("Prefer using `appMessageDictionary`")));
/**
* Creates a formatted time string from a total seconds value, formatted as
* "h:mm:ss".
*
* For example, supplying the value 3930.0f seconds will return @"1:05:30".
*
* @param seconds The number of seconds from which to create the time string.
*
* @return Formatted time as "h:mm:ss"
*
* @deprecated Prefer +[PBSportsUpdate timeStringFromSeconds:].
*/
+ (NSString *)timeStringFromFloat:(float)seconds __attribute__((deprecated("Prefer `+[PBSportsUpdate timeStringFromSeconds:]`")));
@end
@interface PBWatch (SportsDeprecated)
/**
* Send a command to the sports app on the watch that the receiver represents,
* to set the preferred data label (either PACE or SPEED) and corresponding
* units.
*
* Must be called from the main thread.
*
* @param isPace `YES` to request the pace label or `NO` to request the speed
* label.
* @param onSent The handler that will be called when the unit command has been
* sent or timed out (after 1.5 secs).
*
* - `watch`: the recipient of the command.
* - `error`: `nil` if the operation was successful, or else an
* `NSError` with more information on why it failed.
*
* @deprecated Prefer using [PBSportsUpdate pace] or [PBSportsUpdate speed].
*/
- (void)sportsAppSetLabel:(BOOL)isPace onSent:(void(^ __nullable)(PBWatch *watch, NSError *__nullable error))onSent __attribute__((deprecated("Prefer using `[PBSportsUpdate pace]` or `[PBSportsUpdate speed]`")));
/**
* Send a command to the sports app on the watch that the receiver represents,
* to set the preferred unit system, either metric or imperial.
*
* Must be called from the main thread.
*
* @param isMetric `YES` to request metric units or `NO` to request imperial
* units.
* @param onSent The handler that will be called when the unit command has been
* sent or timed out (after 1.5 secs).
*
* - `watch`: the recipient of the command.
* - `error`: `nil` if the operation was successful, or else an
* `NSError` with more information on why it failed.
*
* @deprecated Prefer using [PBWatch(Sports) sportsAppSetUnitSystem:onSent:]
*/
- (void)sportsAppSetMetric:(BOOL)isMetric onSent:(void(^ __nullable)(PBWatch *watch, NSError *__nullable error))onSent __attribute__((deprecated("Prefer using `[PBWatch sportsAppSetUnitSystem:onSent:]`")));
@end
NS_ASSUME_NONNULL_END