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

Commit

Permalink
Prepare for 5.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vbabenkoru committed Jul 10, 2018
1 parent efe72a3 commit 32af84d
Show file tree
Hide file tree
Showing 9 changed files with 389 additions and 150 deletions.
228 changes: 82 additions & 146 deletions Artifacts/include/Iterable-iOS-SDK/IterableAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
// Copyright (c) 2014 Iterable. All rights reserved.
//

@import Foundation;
#import <UIKit/UIKit.h>
#import "CommerceItem.h"
#import "IterableAction.h"
#import "IterableConstants.h"
#import "IterableConfig.h"
#import "IterableAttributionInfo.h"

// all params are nonnull, unless annotated otherwise
NS_ASSUME_NONNULL_BEGIN
Expand All @@ -23,16 +26,6 @@ typedef void (^OnSuccessHandler)(NSDictionary *data);
*/
typedef void (^OnFailureHandler)(NSString *reason, NSData *_Nullable data);

/**
Enum representing push platform; apple push notification service, production vs sandbox
*/
typedef NS_ENUM(NSInteger, PushServicePlatform) {
/** The sandbox push service */
APNS_SANDBOX,
/** The production push service */
APNS
};

/**
`IterableAPI` contains all the essential functions for communicating with Iterable's API
*/
Expand All @@ -42,6 +35,11 @@ typedef NS_ENUM(NSInteger, PushServicePlatform) {
/// @name Properties
////////////////////

/**
SDK Configuration object
*/
@property(nonatomic, readonly) IterableConfig *config;

/**
The apiKey that this IterableAPI is using
*/
Expand All @@ -57,167 +55,92 @@ typedef NS_ENUM(NSInteger, PushServicePlatform) {
*/
@property(nonatomic, readonly, copy) NSString *userId;


/**
The hex representation of this device token
*/
@property(nonatomic, readonly, copy) NSString *hexToken;

/////////////////////////////////
/// @name Creating an IterableAPI
/////////////////////////////////

/*!
@method
@abstract Initializes Iterable with launchOptions
@param apiKey your Iterable apiKey
@param email the email of the user logged in
@param launchOptions launchOptions from application:didFinishLaunchingWithOptions or custom launchOptions
@param useCustomLaunchOptions whether or not to use the custom launchOption without the UIApplicationLaunchOptionsRemoteNotificationKey
@return an instance of IterableAPI
/**
The userInfo dictionary which came with last push.
*/
- (instancetype) initWithApiKey:(NSString *)apiKey andEmail:(NSString *)email launchOptions:(nullable NSDictionary *)launchOptions useCustomLaunchOptions:(BOOL)useCustomLaunchOptions;

/*!
@method
@abstract Initializes Iterable with just an API key and email, but no launchOptions
@param apiKey your Iterable apiKey
@param userId the userId of the user logged in
@return an instance of IterableAPI
@property(nonatomic, readonly, copy, nullable) NSDictionary *lastPushPayload;
/**
Attribution info (campaignId, messageId etc.) for last push open or app link click from an email.
*/
- (instancetype) initWithApiKey:(NSString *)apiKey andUserId:(NSString *) userId;
@property(nonatomic, readwrite, strong, nullable) IterableAttributionInfo *attributionInfo;

/*!
@method
@abstract Initializes Iterable with launchOptions
@param apiKey your Iterable apiKey
@param userId the userId of the user logged in
@param launchOptions launchOptions from application:didFinishLaunchingWithOptions
@return an instance of IterableAPI
*/
- (instancetype) initWithApiKey:(NSString *)apiKey andUserId:(NSString *)userId launchOptions:(nullable NSDictionary *)launchOptions;
/////////////////////////////////
/// @name Initializing IterableAPI
/////////////////////////////////

/*!
@method
@abstract Initializes Iterable with launchOptions
@param apiKey your Iterable apiKey
@param userId the userId of the user logged in
@param launchOptions launchOptions from application:didFinishLaunchingWithOptions or custom launchOptions
@param useCustomLaunchOptions whether or not to use the custom launchOption without the UIApplicationLaunchOptionsRemoteNotificationKey
@return an instance of IterableAPI
/**
* Initializes IterableAPI
* This method must be called from UIApplicationDelegate's `application:didFinishLaunchingWithOptions:`
*
* @note Make sure you also call `setEmail:` or `setUserId:` before making any API calls
* @param apiKey Iterable Mobile API key
* @param launchOptions launchOptions object passed from `application:didFinishLaunchingWithOptions:`
*/
- (instancetype) initWithApiKey:(NSString *)apiKey andUserId:(NSString *)userId launchOptions:(nullable NSDictionary *)launchOptions useCustomLaunchOptions:(BOOL)useCustomLaunchOptions;
+ (void)initializeWithApiKey:(NSString *)apiKey launchOptions:(nullable NSDictionary *)launchOptions;

/*!
@method
@abstract Initializes a shared instance of Iterable with launchOptions
@discussion The sharedInstanceWithApiKey with email is preferred over userId.
This method will set up a singleton instance of the `IterableAPI` class for
you using the given project API key. When you want to make calls to Iterable
elsewhere in your code, you can use `sharedInstance`. If launchOptions is there and
the app was launched from a remote push notification, we will track a pushOpen.
@param apiKey your Iterable apiKey
@param userId the userId of the user logged in
@param launchOptions launchOptions from application:didFinishLaunchingWithOptions
@return an instance of IterableAPI
/**
* Initializes IterableAPI
* This method must be called from UIApplicationDelegate's `application:didFinishLaunchingWithOptions:`
*
* @note Make sure you also call `setEmail:` or `setUserId:` before making any API calls
* @param apiKey Iterable Mobile API key
* @param launchOptions launchOptions object passed from `application:didFinishLaunchingWithOptions:`
* @param config `IterableConfig` object holding SDK configuration options
*/
+ (IterableAPI *) sharedInstanceWithApiKey:(NSString *)apiKey andUserId:(NSString *)userId launchOptions:(nullable NSDictionary *)launchOptions;
+ (void)initializeWithApiKey:(NSString *)apiKey launchOptions:(nullable NSDictionary *)launchOptions config:(IterableConfig *)config;

/*!
@method
@abstract Initializes a shared instance of Iterable with launchOptions
@discussion The sharedInstanceWithApiKey with email is preferred over userId.
This method will set up a singleton instance of the `IterableAPI` class for
you using the given project API key. When you want to make calls to Iterable
elsewhere in your code, you can use `sharedInstance`. If launchOptions is there and
the app was launched from a remote push notification, we will track a pushOpen.
@param apiKey your Iterable apiKey
@param email the email of the user logged in
@param launchOptions launchOptions from application:didFinishLaunchingWithOptions
@return an instance of IterableAPI
*/
+ (IterableAPI *) sharedInstanceWithApiKey:(NSString *)apiKey andEmail:(NSString *)email launchOptions:(nullable NSDictionary *)launchOptions;
/////////////////////////////
/// @name Setting user email or user id
/////////////////////////////

/*!
@method
@abstract Get the previously instantiated singleton instance of the API
@discussion Must be initialized with `sharedInstanceWithApiKey:` before
calling this class method.
@return the existing `IterableAPI` instance
@warning `sharedInstance` will return `nil` if called before calling `sharedInstanceWithApiKey:andEmail:launchOptions:`
/**
* Set user email used for API calls
* Calling this or `setUserId:` is required before making any API calls.
*
* @note This clears userId and persists the user email so you only need to call this once when the user logs in.
* @param email User email
*/
+ (nullable IterableAPI *)sharedInstance;
- (void)setEmail:(nullable NSString *)email;

/*!
@method
@abstract Sets the previously instantiated singleton instance of the API to nil
/**
* Set user ID used for API calls
* Calling this or `setEmail:` is required before making any API calls.
*
* @note This clears user email and persists the user ID so you only need to call this once when the user logs in.
* @param userId User ID
*/
+ (void)clearSharedInstance;
- (void)setUserId:(nullable NSString *)userId;

/////////////////////////////
/// @name Registering a token
/////////////////////////////

/*!
@method
@abstract Register this device's token with Iterable
@param token The token representing this device/application pair, obtained from
/**
* Register this device's token with Iterable
* Push integration name and platform are read from `IterableConfig`. If platform is set to `AUTO`, it will
* read APNS environment from the provisioning profile and use an integration name specified in `IterableConfig`.
* @param token The token representing this device/application pair, obtained from
`application:didRegisterForRemoteNotificationsWithDeviceToken`
after registering for remote notifications
@param appName The application name, as configured in Iterable during set up of the push integration
@param pushServicePlatform The PushServicePlatform to use for this device; dictates whether to register this token in the sandbox or production environment
@see PushServicePlatform
*/
- (void)registerToken:(NSData *)token appName:(NSString *)appName pushServicePlatform:(PushServicePlatform)pushServicePlatform;
- (void)registerToken:(NSData *)token;

/*!
@method
@abstract Register this device's token with Iterable with custom completion blocks
@param token The token representing this device/application pair, obtained from
`application:didRegisterForRemoteNotificationsWithDeviceToken`
after registering for remote notifications
@param appName The application name, as configured in Iterable during set up of the push integration
@param pushServicePlatform The PushServicePlatform to use for this device; dictates whether to register this token in the sandbox or production environment
@param onSuccess OnSuccessHandler to invoke if token registration is successful
@param onFailure OnFailureHandler to invoke if token registration fails
@see PushServicePlatform
@see OnSuccessHandler
@see OnFailureHandler
/**
* Register this device's token with Iterable
* Push integration name and platform are read from `IterableConfig`. If platform is set to `AUTO`, it will
* read APNS environment from the provisioning profile and use an integration name specified in `IterableConfig`.
* @param token The token representing this device/application pair, obtained from
`application:didRegisterForRemoteNotificationsWithDeviceToken`
after registering for remote notifications
* @param onSuccess OnSuccessHandler to invoke if token registration is successful
* @param onFailure OnFailureHandler to invoke if token registration fails
*/
- (void)registerToken:(NSData *)token appName:(NSString *)appName pushServicePlatform:(PushServicePlatform)pushServicePlatform onSuccess:(OnSuccessHandler)onSuccess onFailure:(OnFailureHandler)onFailure;
- (void)registerToken:(NSData *)token onSuccess:(OnSuccessHandler)onSuccess onFailure:(OnFailureHandler)onFailure;

/////////////////////////////
/// @name Disabling a device
Expand Down Expand Up @@ -590,8 +513,21 @@ typedef NS_ENUM(NSInteger, PushServicePlatform) {
@discussion passes the string of the redirected URL to the callback, returns the original webpageURL if not an iterable link
*/
+(void) getAndTrackDeeplink:(NSURL *)webpageURL callbackBlock:(ITEActionBlock)callbackBlock;
+ (void)getAndTrackDeeplink:(NSURL *)webpageURL callbackBlock:(ITEActionBlock)callbackBlock;

/**
* Handles a Universal Link
* For Iterable links, it will track the click and retrieve the original URL,
* pass it to `IterableURLDelegate` for handling
* If it's not an Iterable link, it just passes the same URL to `IterableURLDelegate`
*
* @param url the URL obtained from `[NSUserActivity webpageURL]`
* @return YES if it is an Iterable link, or the value returned from `IterableURLDelegate` otherwise
*/
+ (BOOL)handleUniversalLink:(NSURL *)url;

@end

NS_ASSUME_NONNULL_END

#import "IterableAPI+Deprecated.h"
80 changes: 80 additions & 0 deletions Artifacts/include/Iterable-iOS-SDK/IterableAction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//
// IterableAction.h
// Iterable-iOS-SDK
//
// Created by Victor Babenko on 5/1/18.
// Copyright © 2018 Iterable. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/** Open the URL or deep link */
extern NSString *const IterableActionTypeOpenUrl;

/**
`IterableAction` represents an action defined as a response to user events.
It is currently used in push notification actions (open push & action buttons).
*/
@interface IterableAction : NSObject

////////////////////
/// @name Properties
////////////////////

/**
* Action type
*
* If `IterableActionTypeOpenUrl`, the SDK will call `IterableURLDelegate` and then try to open the URL if
* the delegate returned NO or was not set.
*
* For other types, `IterableCustomActionDelegate` will be called.
*/
@property(nonatomic, readonly) NSString *type;

/**
* Additional data, its content depends on the action type
*/
@property(nonatomic, readonly) NSString *data;

////////////////////
/// @name Optional Fields
////////////////////

/** The text response typed by the user */
@property(nonatomic, readwrite) NSString *userInput;

////////////////////
/// @name Creating IterableAction
////////////////////

/**
* Creates a new `IterableAction` from a dictionary
* @param dictionary Dictionary containing action data
* @return `IterableAction` instance
*/
+ (instancetype)actionFromDictionary:(NSDictionary *)dictionary;

/**
* Creates a new `IterableAction` with type `IterableActionTypeOpenUrl`
* and the specified URL
* @param url URL to open
* @return `IterableAction` instance
*/
+ (instancetype)actionOpenUrl:(NSString *)url;

////////////////////
/// @name Methods
////////////////////

/**
* Checks whether this action is of a specific type
* @param type Action type to match against
* @return Boolean indicating whether the action type matches the one passed to this method
*/
- (BOOL)isOfType:(NSString *)type;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 32af84d

Please sign in to comment.