Skip to content
This repository was archived by the owner on Jul 22, 2020. It is now read-only.

Commit 83cb245

Browse files
authored
Feature/si 112 launch options change (#30)
* Adds in an overloaded function for initWithApiKey to allow for custom launchOptions. * removing unnecessary header for sharedInstance * updating bool type to be compatible w/ objc-swift
1 parent 2459d64 commit 83cb245

File tree

2 files changed

+79
-19
lines changed

2 files changed

+79
-19
lines changed

Iterable-iOS-SDK/IterableAPI.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ typedef NS_ENUM(NSInteger, PushServicePlatform) {
9191
*/
9292
- (instancetype) initWithApiKey:(NSString *)apiKey andEmail:(NSString *)email launchOptions:(nullable NSDictionary *)launchOptions;
9393

94+
/*!
95+
@method
96+
97+
@abstract Initializes Iterable with launchOptions
98+
99+
@param apiKey your Iterable apiKey
100+
@param email the email of the user logged in
101+
@param launchOptions launchOptions from application:didFinishLaunchingWithOptions or custom launchOptions
102+
@param useCustomLaunchOptions whether or not to use the custom launchOption without the UIApplicationLaunchOptionsRemoteNotificationKey
103+
104+
@return an instance of IterableAPI
105+
*/
106+
- (instancetype) initWithApiKey:(NSString *)apiKey andEmail:(NSString *)email launchOptions:(nullable NSDictionary *)launchOptions useCustomLaunchOptions:(BOOL)useCustomLaunchOptions;
107+
94108
/*!
95109
@method
96110
@@ -116,6 +130,20 @@ typedef NS_ENUM(NSInteger, PushServicePlatform) {
116130
*/
117131
- (instancetype) initWithApiKey:(NSString *)apiKey andUserId:(NSString *)userId launchOptions:(nullable NSDictionary *)launchOptions;
118132

133+
/*!
134+
@method
135+
136+
@abstract Initializes Iterable with launchOptions
137+
138+
@param apiKey your Iterable apiKey
139+
@param userId the userId of the user logged in
140+
@param launchOptions launchOptions from application:didFinishLaunchingWithOptions or custom launchOptions
141+
@param useCustomLaunchOptions whether or not to use the custom launchOption without the UIApplicationLaunchOptionsRemoteNotificationKey
142+
143+
@return an instance of IterableAPI
144+
*/
145+
- (instancetype) initWithApiKey:(NSString *)apiKey andUserId:(NSString *)userId launchOptions:(nullable NSDictionary *)launchOptions useCustomLaunchOptions:(BOOL)useCustomLaunchOptions;
146+
119147
/*!
120148
@method
121149

Iterable-iOS-SDK/IterableAPI.m

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -255,19 +255,39 @@ + (OnFailureHandler)defaultOnFailure:(NSString *)identifier
255255
256256
@abstract creates an iterable session with launchOptions
257257
258-
@param launchOptions launchOptions from application:didFinishLaunchingWithOptions
258+
@param launchOptions launchOptions from application:didFinishLaunchingWithOptions
259259
260260
@return an instance of IterableAPI
261261
*/
262262
- (instancetype)createSession:(NSDictionary *)launchOptions
263+
{
264+
return [self createSession:launchOptions useCustomLaunchOptions:false];
265+
}
266+
267+
/*!
268+
@method
269+
270+
@abstract creates an iterable session with launchOptions
271+
272+
@param launchOptions launchOptions from application:didFinishLaunchingWithOptions or custom launchOptions
273+
274+
@param useCustomLaunchOptions whether or not to use the custom launchOption without the UIApplicationLaunchOptionsRemoteNotificationKey
275+
276+
@return an instance of IterableAPI
277+
*/
278+
- (instancetype)createSession:(NSDictionary *)launchOptions useCustomLaunchOptions:(BOOL)useCustomLaunchOptions
263279
{
264280
// the url session doesn't depend on any options/params, so we'll use a singleton that gets created whenever the class is instantiated
265281
// if it gets instantiated again that's fine; we don't need to reconfigure the session, just keep using the old singleton
266282
[self createUrlSession];
267283

268-
if (launchOptions && launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {
269-
// Automatically try to track a pushOpen
270-
[self trackPushOpen:launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]];
284+
// Automatically try to track a pushOpen
285+
if (launchOptions) {
286+
if (useCustomLaunchOptions) {
287+
[self trackPushOpen:launchOptions];
288+
} else if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {
289+
[self trackPushOpen:launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]];
290+
}
271291
}
272292

273293
return self;
@@ -277,37 +297,49 @@ - (instancetype)createSession:(NSDictionary *)launchOptions
277297
/// @name Implementations of things documents in IterableAPI.h
278298
//////////////////////////////////////////////////////////////
279299

300+
// documented in IterableAPI.h
301+
- (instancetype)initWithApiKey:(NSString *)apiKey andEmail:(NSString *)email
302+
{
303+
return [self initWithApiKey:apiKey andEmail:email launchOptions:nil];
304+
}
305+
306+
// documented in IterableAPI.h
307+
- (instancetype)initWithApiKey:(NSString *)apiKey andUserId:(NSString *)userId
308+
{
309+
return [self initWithApiKey:apiKey andUserId:userId launchOptions:nil];
310+
}
311+
280312
// documented in IterableAPI.h
281313
- (instancetype)initWithApiKey:(NSString *)apiKey andEmail:(NSString *)email launchOptions:(NSDictionary *)launchOptions
282314
{
283-
if (self = [super init]) {
284-
_apiKey = [apiKey copy];
285-
_email = [email copy];
286-
}
287-
288-
return [self createSession:launchOptions];
315+
return [self initWithApiKey:apiKey andEmail:email launchOptions:launchOptions useCustomLaunchOptions:false];
289316
}
290317

291318
// documented in IterableAPI.h
292319
- (instancetype)initWithApiKey:(NSString *)apiKey andUserId:(NSString *)userId launchOptions:(NSDictionary *)launchOptions
293320
{
294-
if (self = [super init]) {
295-
_apiKey = [apiKey copy];
296-
_userId = [userId copy];
297-
}
298-
return [self createSession:launchOptions];
321+
return [self initWithApiKey:apiKey andUserId:userId launchOptions:launchOptions useCustomLaunchOptions:false];
299322
}
300323

301324
// documented in IterableAPI.h
302-
- (instancetype)initWithApiKey:(NSString *)apiKey andEmail:(NSString *)email
325+
- (instancetype)initWithApiKey:(NSString *)apiKey andEmail:(NSString *)email launchOptions:(NSDictionary *)launchOptions useCustomLaunchOptions:(BOOL)useCustomLaunchOptions
303326
{
304-
return [self initWithApiKey:apiKey andEmail:email launchOptions:nil];
327+
if (self = [super init]) {
328+
_apiKey = [apiKey copy];
329+
_email = [email copy];
330+
}
331+
332+
return [self createSession:launchOptions useCustomLaunchOptions:useCustomLaunchOptions];
305333
}
306334

307335
// documented in IterableAPI.h
308-
- (instancetype)initWithApiKey:(NSString *)apiKey andUserId:(NSString *)userId
336+
- (instancetype)initWithApiKey:(NSString *)apiKey andUserId:(NSString *)userId launchOptions:(NSDictionary *)launchOptions useCustomLaunchOptions:(BOOL)useCustomLaunchOptions
309337
{
310-
return [self initWithApiKey:apiKey andUserId:userId launchOptions:nil];
338+
if (self = [super init]) {
339+
_apiKey = [apiKey copy];
340+
_userId = [userId copy];
341+
}
342+
return [self createSession:launchOptions useCustomLaunchOptions:useCustomLaunchOptions];
311343
}
312344

313345
// documented in IterableAPI.h

0 commit comments

Comments
 (0)