-
Notifications
You must be signed in to change notification settings - Fork 38
/
NYT360MotionManagement.h
91 lines (71 loc) · 3.37 KB
/
NYT360MotionManagement.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
//
// NYT360MotionManagement.h
// NYT360Video
//
// Created by Jared Sinclair on 8/3/16.
// Copyright © 2016 The New York Times Company. All rights reserved.
//
@import Foundation;
@import CoreMotion;
NS_ASSUME_NONNULL_BEGIN
typedef id<NSObject, NSCopying> NYT360MotionManagementToken;
/**
Expectations that must be fulfilled by an appliation-wide "wrapper" around
CMMotionManager for NYT360Video's use.
Per Apple's documentation, it is recommended that an application will have no
more than one `CMMotionManager`, otherwise performance could degrade. The
challenge for the host application using NYT360Video is that there may be
entities outside of NYT360Video that also require device motion updates. It is
undesirable that all these entities would have direct access to the same shared
manager, leading to misconfigurations or a premature call to
`stopDeviceMotionUpdates`. To facilitate the use of a shared motion manager
without exposing a surface area for misuse, the `NYT360MotionManagement` protocol
defines a set of expectations for a shared "wrapper" around a shared
`CMMotionManager`. The conforming class must ensure that a shared
`CMMotionManager` is kept private, properly configured, and activated or
deactivated at the appropriate times.
A host application is free to provide a custom class conforming to
`NYT360MotionManagement`. If your application does not use a CMMotionManager
outside of NYT360Videos, we recommend that you use the shared instance of
`NYT360MotionManager`, a ready-made class that already conforms to
`NYT360MotionManagement`.
@seealso `NYT360MotionManager.h`
*/
@protocol NYT360MotionManagement <NSObject>
/**
Determines whether device motion hardware and APIs are available.
*/
@property (nonatomic, readonly, getter=isDeviceMotionAvailable) BOOL deviceMotionAvailable;
/**
Determines whether the receiver is currently providing motion updates.
*/
@property (nonatomic, readonly, getter=isDeviceMotionActive) BOOL deviceMotionActive;
/**
Returns the latest sample of device motion data, or nil if none is available.
*/
@property (nonatomic, readonly, nullable) CMDeviceMotion *deviceMotion;
/**
Begins updating device motion, if it hasn't begun already.
@param preferredUpdateInterval The requested update interval. The actual
interval used should resolve to the shortest requested interval among the
active requests.
@return Returns a token which the caller should use to balance this call with a
call to `stopUpdating:`.
@warning Callers should balance a call to `startUpdating` with a call to
`stopUpdating:`, otherwise device motion will continue to be updated indefinitely.
*/
- (NYT360MotionManagementToken)startUpdating:(NSTimeInterval)preferredUpdateInterval;
/**
Requests that device motion updates be stopped. If there are other active
observers that still require device motion updates, motion updates will not be
stopped.
The device motion update interval may be raised or lowered after a call to
`stopUpdating:`, as the interval will resolve to the shortest interval among
the active observers.
@param identifier The token received from a call to `startUpdating`.
@warning Callers should balance a call to `startUpdating` with a call to
`stopUpdating:`, otherwise device motion will continue to be updated indefinitely.
*/
- (void)stopUpdating:(NYT360MotionManagementToken)token;
@end
NS_ASSUME_NONNULL_END