|
| 1 | +// |
| 2 | +// Iterable_API.h |
| 3 | +// Iterable-iOS-SDK |
| 4 | +// |
| 5 | +// Created by Ilya Brin on 11/19/14. |
| 6 | +// Copyright (c) 2014 Iterable. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +@import Foundation; |
| 10 | +#import "CommerceItem.h" |
| 11 | + |
| 12 | +// all params are nonnull, unless annotated otherwise |
| 13 | +NS_ASSUME_NONNULL_BEGIN |
| 14 | + |
| 15 | +/** |
| 16 | + The prototype for the completion handler block that gets called when an Iterable call is successful |
| 17 | + */ |
| 18 | +typedef void (^OnSuccessHandler)(NSDictionary *data); |
| 19 | + |
| 20 | +/** |
| 21 | + The prototype for the completion handler block that gets called when an Iterable call fails |
| 22 | + */ |
| 23 | +typedef void (^OnFailureHandler)(NSString *reason, NSData *data); |
| 24 | + |
| 25 | +/** |
| 26 | + Enum representing push platform; apple push notification service, production vs sandbox |
| 27 | + */ |
| 28 | +typedef NS_ENUM(NSInteger, PushServicePlatform) { |
| 29 | + /** The sandbox push service */ |
| 30 | + APNS_SANDBOX, |
| 31 | + /** The production push service */ |
| 32 | + APNS |
| 33 | +}; |
| 34 | + |
| 35 | +/** |
| 36 | + `IterableAPI` contains all the essential functions for communicating with Iterable's API |
| 37 | + */ |
| 38 | +@interface IterableAPI : NSObject |
| 39 | + |
| 40 | +//////////////////// |
| 41 | +/// @name Properties |
| 42 | +//////////////////// |
| 43 | + |
| 44 | +/** |
| 45 | + The apiKey that this IterableAPI is using |
| 46 | + */ |
| 47 | +@property(nonatomic, readonly, copy) NSString *apiKey; |
| 48 | + |
| 49 | +/** |
| 50 | + The email of the logged in user that this IterableAPI is using |
| 51 | + */ |
| 52 | +@property(nonatomic, readonly, copy) NSString *email; |
| 53 | + |
| 54 | + |
| 55 | +///////////////////////////////// |
| 56 | +/// @name Creating an IterableAPI |
| 57 | +///////////////////////////////// |
| 58 | + |
| 59 | +/*! |
| 60 | + @method |
| 61 | + |
| 62 | + @abstract Initializes Iterable with just an API key and email, but no launchOptions |
| 63 | + |
| 64 | + @param apiKey your Iterable apiKey |
| 65 | + @param email the email of the user logged in |
| 66 | + |
| 67 | + @return an instance of IterableAPI |
| 68 | + */ |
| 69 | +- (instancetype) initWithApiKey:(NSString *)apiKey andEmail:(NSString *) email; |
| 70 | + |
| 71 | +/*! |
| 72 | + @method |
| 73 | + |
| 74 | + @abstract Initializes Iterable with launchOptions |
| 75 | + |
| 76 | + @param apiKey your Iterable apiKey |
| 77 | + @param email the email of the user logged in |
| 78 | + @param launchOptions launchOptions from application:didFinishLaunchingWithOptions |
| 79 | + |
| 80 | + @return an instance of IterableAPI |
| 81 | + */ |
| 82 | +- (instancetype) initWithApiKey:(NSString *)apiKey andEmail:(NSString *)email launchOptions:(nullable NSDictionary *)launchOptions; |
| 83 | + |
| 84 | +/*! |
| 85 | + @method |
| 86 | + |
| 87 | + @abstract Initializes a shared instance of Iterable with launchOptions |
| 88 | + |
| 89 | + @discussion This method will set up a singleton instance of the `IterableAPI` class for |
| 90 | + you using the given project API key. When you want to make calls to Iterable |
| 91 | + elsewhere in your code, you can use `sharedInstance`. If launchOptions is there and |
| 92 | + the app was launched from a remote push notification, we will track a pushOpen. |
| 93 | + |
| 94 | + @param apiKey your Iterable apiKey |
| 95 | + @param email the email of the user logged in |
| 96 | + @param launchOptions launchOptions from application:didFinishLaunchingWithOptions |
| 97 | + |
| 98 | + @return an instance of IterableAPI |
| 99 | + */ |
| 100 | ++ (IterableAPI *) sharedInstanceWithApiKey:(NSString *)apiKey andEmail:(NSString *)email launchOptions:(nullable NSDictionary *)launchOptions; |
| 101 | + |
| 102 | +/*! |
| 103 | + @method |
| 104 | + |
| 105 | + @abstract Get the previously instantiated singleton instance of the API |
| 106 | + |
| 107 | + @discussion Must be initialized with `sharedInstanceWithApiKey:` before |
| 108 | + calling this class method. |
| 109 | + |
| 110 | + @return the existing `IterableAPI` instance |
| 111 | + |
| 112 | + @warning `sharedInstance` will return `nil` if called before calling `sharedInstanceWithApiKey:andEmail:launchOptions:` |
| 113 | + */ |
| 114 | ++ (nullable IterableAPI *)sharedInstance; |
| 115 | + |
| 116 | +///////////////////////////// |
| 117 | +/// @name Registering a token |
| 118 | +///////////////////////////// |
| 119 | + |
| 120 | +/*! |
| 121 | + @method |
| 122 | + |
| 123 | + @abstract Register this device's token with Iterable |
| 124 | +
|
| 125 | + @param token The token representing this device/application pair, obtained from |
| 126 | + `application:didRegisterForRemoteNotificationsWithDeviceToken` |
| 127 | + after registering for remote notifications |
| 128 | + @param appName The application name, as configured in Iterable during set up of the push integration |
| 129 | + @param pushServicePlatform The PushServicePlatform to use for this device; dictates whether to register this token in the sandbox or production environment |
| 130 | + |
| 131 | + @see PushServicePlatform |
| 132 | + |
| 133 | + */ |
| 134 | +- (void)registerToken:(NSData *)token appName:(NSString *)appName pushServicePlatform:(PushServicePlatform)pushServicePlatform; |
| 135 | + |
| 136 | +/*! |
| 137 | + @method |
| 138 | + |
| 139 | + @abstract Register this device's token with Iterable with custom completion blocks |
| 140 | + |
| 141 | + @param token The token representing this device/application pair, obtained from |
| 142 | + `application:didRegisterForRemoteNotificationsWithDeviceToken` |
| 143 | + after registering for remote notifications |
| 144 | + @param appName The application name, as configured in Iterable during set up of the push integration |
| 145 | + @param pushServicePlatform The PushServicePlatform to use for this device; dictates whether to register this token in the sandbox or production environment |
| 146 | + @param onSuccess OnSuccessHandler to invoke if token registration is successful |
| 147 | + @param onFailure OnFailureHandler to invoke if token registration fails |
| 148 | + |
| 149 | + @see PushServicePlatform |
| 150 | + @see OnSuccessHandler |
| 151 | + @see OnFailureHandler |
| 152 | + */ |
| 153 | +- (void)registerToken:(NSData *)token appName:(NSString *)appName pushServicePlatform:(PushServicePlatform)pushServicePlatform onSuccess:(OnSuccessHandler)onSuccess onFailure:(OnFailureHandler)onFailure; |
| 154 | + |
| 155 | +///////////////////////// |
| 156 | +/// @name Tracking events |
| 157 | +///////////////////////// |
| 158 | + |
| 159 | +/*! |
| 160 | + @method |
| 161 | + |
| 162 | + @abstract Tracks a purchase |
| 163 | + |
| 164 | + @discussion Pass in the total purchase amount and an `NSArray` of `CommerceItem`s |
| 165 | + |
| 166 | + @param total total purchase amount |
| 167 | + @param items list of purchased items |
| 168 | + |
| 169 | + @see CommerceItem |
| 170 | + */ |
| 171 | +- (void)trackPurchase:(NSNumber *)total items:(NSArray<CommerceItem *>*)items; |
| 172 | + |
| 173 | +/*! |
| 174 | + @method |
| 175 | + |
| 176 | + @abstract Tracks a purchase with additional data |
| 177 | + |
| 178 | + @discussion Pass in the total purchase amount and an `NSArray` of `CommerceItem`s |
| 179 | + |
| 180 | + @param total total purchase amount |
| 181 | + @param items list of purchased items |
| 182 | + @param dataFields an `NSDictionary` containing any additional information to save along with the event |
| 183 | + |
| 184 | + @see CommerceItem |
| 185 | + */ |
| 186 | +- (void)trackPurchase:(NSNumber *)total items:(NSArray<CommerceItem *>*)items dataFields:(nullable NSDictionary *)dataFields; |
| 187 | + |
| 188 | +/*! |
| 189 | + @method |
| 190 | + |
| 191 | + @abstract Tracks a purchase with additional data and custom completion blocks |
| 192 | + |
| 193 | + @discussion Pass in the total purchase amount and an `NSArray` of `CommerceItem`s |
| 194 | + |
| 195 | + @param total total purchase amount |
| 196 | + @param items list of purchased items |
| 197 | + @param dataFields an `NSDictionary` containing any additional information to save along with the event |
| 198 | + @param onSuccess OnSuccessHandler to invoke if the purchase is tracked successfully |
| 199 | + @param onFailure OnFailureHandler to invoke if tracking the purchase fails |
| 200 | + |
| 201 | + @see CommerceItem |
| 202 | + @see OnSuccessHandler |
| 203 | + @see OnFailureHandler |
| 204 | + */ |
| 205 | +- (void)trackPurchase:(NSNumber *)total items:(NSArray<CommerceItem *>*)items dataFields:(nullable NSDictionary *)dataFields onSuccess:(OnSuccessHandler)onSuccess onFailure:(OnFailureHandler)onFailure; |
| 206 | + |
| 207 | +/*! |
| 208 | + @method |
| 209 | + |
| 210 | + @abstract Tracks a pushOpen event with a push notification payload |
| 211 | + |
| 212 | + @discussion Pass in the `userInfo` from the push notification payload |
| 213 | + |
| 214 | + @param userInfo the push notification payload |
| 215 | + */ |
| 216 | +- (void)trackPushOpen:(NSDictionary *)userInfo; |
| 217 | + |
| 218 | +/*! |
| 219 | + @method |
| 220 | + |
| 221 | + @abstract Tracks a pushOpen event with a push notification and optional additional data |
| 222 | + |
| 223 | + @discussion Pass in the `userInfo` from the push notification payload |
| 224 | + |
| 225 | + @param userInfo the push notification payload |
| 226 | + @param dataFields an `NSDictionary` containing any additional information to save along with the event |
| 227 | + */ |
| 228 | +- (void)trackPushOpen:(NSDictionary *)userInfo dataFields:(nullable NSDictionary *)dataFields; |
| 229 | + |
| 230 | +/*! |
| 231 | + @method |
| 232 | + |
| 233 | + @abstract Tracks a pushOpen event with a push notification, optional additional data, and custom completion blocks |
| 234 | + |
| 235 | + @discussion Pass in the `userInfo` from the push notification payload |
| 236 | + |
| 237 | + @param userInfo the push notification payload |
| 238 | + @param dataFields an `NSDictionary` containing any additional information to save along with the event |
| 239 | + @param onSuccess OnSuccessHandler to invoke if the open is tracked successfully |
| 240 | + @param onFailure OnFailureHandler to invoke if tracking the open fails |
| 241 | + |
| 242 | + @see OnSuccessHandler |
| 243 | + @see OnFailureHandler |
| 244 | + */ |
| 245 | +- (void)trackPushOpen:(NSDictionary *)userInfo dataFields:(nullable NSDictionary *)dataFields onSuccess:(OnSuccessHandler)onSuccess onFailure:(OnFailureHandler)onFailure; |
| 246 | + |
| 247 | +/*! |
| 248 | + @method |
| 249 | + |
| 250 | + @abstract Tracks a pushOpen event for the specified campaign and template ids, whether the app was already running when the push was received, and optional additional data |
| 251 | + |
| 252 | + @discussion Pass in the the relevant campaign data |
| 253 | + |
| 254 | + @param campaignId The campaignId of the the push notification that caused this open event |
| 255 | + @param templateId The templateId of the the push notification that caused this open event |
| 256 | + @param appAlreadyRunning This will get merged into the dataFields. Whether the app is already running when the notification was received |
| 257 | + @param dataFields An `NSDictionary` containing any additional information to save along with the event |
| 258 | + */ |
| 259 | +- (void)trackPushOpen:(NSNumber *)campaignId templateId:(NSNumber *)templateId appAlreadyRunning:(BOOL)appAlreadyRunning dataFields:(nullable NSDictionary *)dataFields; |
| 260 | + |
| 261 | +/*! |
| 262 | + @method |
| 263 | + |
| 264 | + @abstract Tracks a pushOpen event for the specified campaign and template ids, whether the app was already running when the push was received, and optional additional data, with custom completion blocks |
| 265 | + |
| 266 | + @discussion Pass in the the relevant campaign data |
| 267 | + |
| 268 | + @param campaignId The campaignId of the the push notification that caused this open event |
| 269 | + @param templateId The templateId of the the push notification that caused this open event |
| 270 | + @param appAlreadyRunning This will get merged into the dataFields. Whether the app is already running when the notification was received |
| 271 | + @param dataFields An `NSDictionary` containing any additional information to save along with the event |
| 272 | + @param onSuccess OnSuccessHandler to invoke if the open is tracked successfully |
| 273 | + @param onFailure OnFailureHandler to invoke if tracking the open fails |
| 274 | + |
| 275 | + @see OnSuccessHandler |
| 276 | + @see OnFailureHandler |
| 277 | + */ |
| 278 | +- (void)trackPushOpen:(NSNumber *)campaignId templateId:(NSNumber *)templateId appAlreadyRunning:(BOOL)appAlreadyRunning dataFields:(nullable NSDictionary *)dataFields onSuccess:(OnSuccessHandler)onSuccess onFailure:(OnFailureHandler)onFailure; |
| 279 | + |
| 280 | +/*! |
| 281 | + @method |
| 282 | + |
| 283 | + @abstract Tracks a custom event. |
| 284 | + |
| 285 | + @discussion Pass in the the custom event data. |
| 286 | + |
| 287 | + @param eventName Name of the event |
| 288 | + */ |
| 289 | +- (void)track:(NSString *)eventName; |
| 290 | + |
| 291 | +/*! |
| 292 | + @method |
| 293 | + |
| 294 | + @abstract Tracks a custom event with optional additional fields |
| 295 | + |
| 296 | + @discussion Pass in the the custom event data. |
| 297 | + |
| 298 | + @param eventName Name of the event |
| 299 | + @param dataFields An `NSDictionary` containing any additional information to save along with the event |
| 300 | + */ |
| 301 | +- (void)track:(NSString *)eventName dataFields:(nullable NSDictionary *)dataFields; |
| 302 | + |
| 303 | +/*! |
| 304 | + @method |
| 305 | + |
| 306 | + @abstract Tracks a custom event with optional additional fields and custom completion blocks |
| 307 | + |
| 308 | + @discussion Pass in the the custom event data. |
| 309 | + |
| 310 | + @param eventName Name of the event |
| 311 | + @param dataFields An `NSDictionary` containing any additional information to save along with the event |
| 312 | + @param onSuccess OnSuccessHandler to invoke if the track call succeeds |
| 313 | + @param onFailure OnFailureHandler to invoke if the track call fails |
| 314 | + |
| 315 | + @see OnSuccessHandler |
| 316 | + @see OnFailureHandler |
| 317 | + */ |
| 318 | +- (void)track:(NSString *)eventName dataFields:(nullable NSDictionary *)dataFields onSuccess:(OnSuccessHandler)onSuccess onFailure:(OnFailureHandler)onFailure; |
| 319 | + |
| 320 | +@end |
| 321 | + |
| 322 | +NS_ASSUME_NONNULL_END |
0 commit comments