ConnectIQ.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. //
  2. // ConnectIQ.h
  3. // ConnectIQ
  4. //
  5. // Copyright (c) 2014 Garmin. All rights reserved.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #import "IQConstants.h"
  9. #import "IQDevice.h"
  10. #import "IQApp.h"
  11. // --------------------------------------------------------------------------------
  12. #pragma mark - PUBLIC TYPES
  13. // --------------------------------------------------------------------------------
  14. /// @brief SendMessage progress callback block
  15. ///
  16. /// @param sentBytes The number of bytes that have been successfully transferred
  17. /// to the device so far for this connection.
  18. /// @param totalBytes The total number of bytes to transfer for this connection.
  19. typedef void (^IQSendMessageProgress)(uint32_t sentBytes, uint32_t totalBytes);
  20. /// @brief SendMessage completion callback block
  21. ///
  22. /// @param result The result of the SendMessage operation.
  23. typedef void (^IQSendMessageCompletion)(IQSendMessageResult result);
  24. /// @brief Conforming to the IQUIOverrideDelegate protocol indicates that an
  25. /// object handles one or more events triggered by the ConnectIQ SDK that
  26. /// require user input.
  27. @protocol IQUIOverrideDelegate <NSObject>
  28. @optional
  29. /// @brief Called by the ConnectIQ SDK when an action has been requested that
  30. /// requires Garmin Connect Mobile to be installed.
  31. ///
  32. /// The receiver should choose whether or not to launch the Apple App
  33. /// Store page for GCM, ideally by presenting the user with a choice.
  34. ///
  35. /// If the receiver of this message decides to install GCM, it must call
  36. /// showAppStoreForConnectMobile.
  37. - (void)needsToInstallConnectMobile;
  38. @end
  39. /// @brief Conforming to the IQDeviceEventDelegate protocol indicates that an
  40. /// object handles ConnectIQ device status events.
  41. @protocol IQDeviceEventDelegate <NSObject>
  42. @optional
  43. /// @brief Called by the ConnectIQ SDK when an IQDevice's connection status has
  44. /// changed.
  45. ///
  46. /// @param device The IQDevice whose status changed.
  47. /// @param status The new status of the device.
  48. - (void)deviceStatusChanged:(IQDevice *)device status:(IQDeviceStatus)status;
  49. @end
  50. /// @brief Conforming to the IQAppMessageDelegate protocol indicates that an
  51. /// object handles messages from ConnectIQ apps on compatible devices.
  52. @protocol IQAppMessageDelegate <NSObject>
  53. @optional
  54. /// @brief Called by the ConnectIQ SDK when a message is received from a device.
  55. ///
  56. /// @param message The message that was received.
  57. /// @param app The device app that sent the message.
  58. - (void)receivedMessage:(id)message fromApp:(IQApp *)app;
  59. @end
  60. // --------------------------------------------------------------------------------
  61. #pragma mark - CLASS DEFINITION
  62. // --------------------------------------------------------------------------------
  63. /// @brief The root of the ConnectIQ SDK API.
  64. @interface ConnectIQ : NSObject
  65. + (instancetype)new NS_UNAVAILABLE;
  66. - (instancetype)init NS_UNAVAILABLE;
  67. // --------------------------------------------------------------------------------
  68. #pragma mark - SINGLETON ACCESS
  69. // --------------------------------------------------------------------------------
  70. /// @brief Exposes the single static instance of the ConnectIQ class.
  71. ///
  72. /// @return The single status instance of the ConnectIQ class.
  73. + (ConnectIQ *)sharedInstance;
  74. // --------------------------------------------------------------------------------
  75. #pragma mark - INITIALIZATION
  76. // --------------------------------------------------------------------------------
  77. /// @brief Initializes the ConnectIQ SDK with startup parameters necessary for
  78. /// its operation.
  79. ///
  80. /// @param urlScheme The URL scheme for this companion app. When Garmin Connect
  81. /// Mobile is launched, it will return to the companion app by
  82. /// launching a URL with this scheme.
  83. /// @param delegate The delegate that the SDK will use for notifying the
  84. /// companion app about events that require user input. If this
  85. /// is nil, the SDK's default UI will be used.
  86. - (void)initializeWithUrlScheme:(NSString *)urlScheme uiOverrideDelegate:(id<IQUIOverrideDelegate>)delegate;
  87. // --------------------------------------------------------------------------------
  88. #pragma mark - EXTERNAL LAUNCHING
  89. // --------------------------------------------------------------------------------
  90. /// @brief Launches the Apple App Store page for the Garmin Connect Mobile app.
  91. /// The companion app should only call this in response to a
  92. /// needsToInstallConnectMobile event that gets triggered on the
  93. /// IQUIOverrideDelegate.
  94. - (void)showAppStoreForConnectMobile;
  95. /// @brief Launches Garmin Connect Mobile for the purpose of retrieving a list of
  96. /// ConnectIQ-compatible devices.
  97. ///
  98. /// Once the user has chosen which ConnectIQ devices to share with the
  99. /// companion app, GCM will return those devices to the companion app by
  100. /// opening a URL with the scheme registered in
  101. /// initializeWithUrlScheme:uiOverrideDelegate:.
  102. ///
  103. /// The companion app should handle this URL by passing it in to the
  104. /// parseDeviceSelectionResponseFromURL: method to get the list of devices
  105. /// that the user permitted the companion app to communicate with.
  106. - (void)showConnectIQDeviceSelection;
  107. /// @brief Parses a URL opened from Garmin Connect Mobile into a list of devices.
  108. ///
  109. /// @param url The URL to parse.
  110. ///
  111. /// @return An array of IQDevice objects representing the ConnectIQ-compatible
  112. /// devices that the user allowed GCM to share with the companion app.
  113. ///
  114. /// @seealso showConnectIQDeviceSelection
  115. - (NSArray *)parseDeviceSelectionResponseFromURL:(NSURL *)url;
  116. /// @brief Launches Garmin Connect Mobile and shows the ConnectIQ app store page
  117. /// for the given app.
  118. ///
  119. /// The companion app should call this if the user would like to manage
  120. /// the app on the device, such as to install, upgrade, uninstall, or
  121. /// modify settings.
  122. ///
  123. /// @param app The app to show the ConnectIQ app store page for.
  124. - (void)showConnectIQStoreForApp:(IQApp *)app;
  125. // --------------------------------------------------------------------------------
  126. #pragma mark - DEVICE MANAGEMENT
  127. // --------------------------------------------------------------------------------
  128. /// @brief Registers an object as a listener for ConnectIQ device status events.
  129. ///
  130. /// A device may have multiple device event listeners if this method is
  131. /// called more than once.
  132. ///
  133. /// @param device A device to listen for status events from.
  134. /// @param delegate The listener which will receive status events for this device.
  135. - (void)registerForDeviceEvents:(IQDevice *)device delegate:(id<IQDeviceEventDelegate>)delegate;
  136. /// @brief Unregisters a listener for a specific device.
  137. ///
  138. /// @param device The device to unregister the listener for.
  139. /// @param delegate The listener to remove from the device.
  140. - (void)unregisterForDeviceEvents:(IQDevice *)device delegate:(id<IQDeviceEventDelegate>)delegate;
  141. /// @brief Unregisters the specified listener from all devices for which it had
  142. /// previously been registered.
  143. ///
  144. /// @param delegate The listener to unregister.
  145. - (void)unregisterForAllDeviceEvents:(id<IQDeviceEventDelegate>)delegate;
  146. /// @brief Gets the current connection status of a device.
  147. ///
  148. /// The device must have been registered for event notifications by
  149. /// calling registerForDeviceEvents:delegate: or this method will return
  150. /// IQDeviceStatus_InvalidDevice.
  151. ///
  152. /// @param device The device to get the status for.
  153. ///
  154. /// @return The device's current connection status.
  155. - (IQDeviceStatus)getDeviceStatus:(IQDevice *)device;
  156. // --------------------------------------------------------------------------------
  157. #pragma mark - APP MANAGEMENT
  158. // --------------------------------------------------------------------------------
  159. /// @brief Begins getting the status of an app on a device. This method returns
  160. /// immediately.
  161. ///
  162. /// @param app The IQApp to get the status for.
  163. /// @param completion The completion block that will be triggered when the device
  164. /// status operation is complete.
  165. - (void)getAppStatus:(IQApp *)app completion:(void(^)(IQAppStatus *appStatus))completion;
  166. /// @brief Registers an object as a listener for ConnectIQ messages from an app
  167. /// on a device.
  168. ///
  169. /// An app may have multiple message listeners if this method is called
  170. /// more than once.
  171. ///
  172. /// @param app The app to listen for messages from.
  173. /// @param delegate The listener which will receive messages for this app.
  174. - (void)registerForAppMessages:(IQApp *)app delegate:(id<IQAppMessageDelegate>)delegate;
  175. /// @brief Unregisters a listener for a specific app.
  176. ///
  177. /// @param app The app to unregister a listener for.
  178. /// @param delegate The listener to remove from the app.
  179. - (void)unregisterForAppMessages:(IQApp *)app delegate:(id<IQAppMessageDelegate>)delegate;
  180. /// @brief Unregisters all previously registered apps for a specific listener.
  181. ///
  182. /// @param delegate The listener to unregister.
  183. - (void)unregisterForAllAppMessages:(id<IQAppMessageDelegate>)delegate;
  184. /// @brief Begins sending a message to an app. This method returns immediately.
  185. ///
  186. /// @param message The message to send to the app. This message must be one of
  187. /// the following types: NSString, NSNumber, NSNull, NSArray,
  188. /// or NSDictionary. Arrays and dictionaries may be nested.
  189. /// @param app The app to send the message to.
  190. /// @param progress A progress block that will be triggered periodically
  191. /// throughout the transfer. This is guaranteed to be triggered
  192. /// at least once.
  193. /// @param completion A completion block that will be triggered when the send
  194. /// message operation is complete.
  195. - (void)sendMessage:(id)message toApp:(IQApp *)app progress:(IQSendMessageProgress)progress completion:(IQSendMessageCompletion)completion;
  196. /// @brief Sends an open app request message request to the device. This method returns immediately.
  197. ///
  198. /// @param app The app to open.
  199. /// @param completion A completion block that will be triggered when the send
  200. /// message operation is complete.
  201. - (void)openAppRequest:(IQApp *)app completion:(IQSendMessageCompletion)completion;
  202. // TODO *** Holding off on documenting this until this method actually works.
  203. - (void)sendImage:(NSData *)bitmap toApp:(IQApp *)app progress:(IQSendMessageProgress)progress completion:(IQSendMessageCompletion)completion;
  204. @end