WLPushManager.h 10.2 KB
/*
 Copyright 2010-2016 Warply Inc. All rights reserved.
 
 Redistribution and use in source and binary forms, without modification, 
 are permitted provided that the following conditions are met:
 
 1. Redistributions of source code must retain the above copyright notice, this
 list of conditions and the following disclaimer.
 
 2. Redistributions in binaryform must reproduce the above copyright notice,
 this list of conditions and the following disclaimer in the documentation
 and/or other materials provided with the distribution.
 
 THIS SOFTWARE IS PROVIDED BY THE WARPLY LTD ``AS IS'' AND ANY EXPRESS OR
 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
 EVENT SHALL WARPLY LTD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*!
 @header WLPushManager.h
 The Push Manager provides a functional interface for handling push notifications.
 @copyright Warply Inc.
 */

@import UIKit;
#import <Foundation/Foundation.h>
#import "WLBaseItem.h"
#import "WLInboxItem.h"
#import <UserNotifications/UserNotifications.h>

@class Warply;
@protocol WLCustomPushHandler;

/*!
 @typedef WLApplicationState
 @abstract States in which the app can receive a remote push notification.
 @field WLApplicationStateActive The application is running in the foreground and currently receiving events.
 @field WLApplicationStateClosed The application is closed.
 @field WLApplicationStateBackground The application is running in the background.
 */
typedef enum WLApplicationState : unsigned int{
    WLApplicationStateActive,
    WLApplicationStateClosed,
    WLApplicationStateBackground
}WLApplicationState;

/*!
 @class WLUserManager
 @discussion This manager handles the Remote Notifications (Push) functionality 
 of Warply service.By default it displays remote notifications that have action == 0 by displaying the rich push content in a webview. You can chοose to handle push notifications in a custom manner. To do this, send a remote notification with action != 0 from the Warply server and set the @link //apple_ref/occ/instp/Warply/customPushHanlder customPushHandler @/link property with your custom object that conforms to the @link //apple_ref/occ/instp/Warply/WLCustomPushHandler WLCustomPushHandler @/link protocol.
 */
@interface WLPushManager : NSObject <UNUserNotificationCenterDelegate>
{
    //Settings
    NSString *_deviceToken;
}

/*!
 @property hasSentDeviceInfo.
 @abstract Returns YES if the device info/application data has been sent during this session.
 */
@property (nonatomic) BOOL hasSentDeviceInfo;

/*!
 @property isMissingDeviceInfo.
 @abstract Returns YES if the device info/application data has been sent during this session.
 */
@property (nonatomic) BOOL isMissingDeviceInfo;

/*!
 @property deviceToken
 @abstract The device token property.
 */
@property (nonatomic, readonly) NSString *deviceToken;


/*!
 @property notificationTypes
 @abstract A UIRemoteNotificationType property.
 */
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
@property (nonatomic, readonly) UIRemoteNotificationType notificationTypes;
#pragma clang diagnostic pop

@property (nonatomic, readonly) UNAuthorizationOptions notificationOptions;

/*!
 @property pendingItem
 @abstract The remote notification as a WLBaseItem currently stored for later use. 
 */
@property (nonatomic, strong) WLBaseItem *pendingItem;

/*!
 @property customPushHanlder
 @abstract A WLConsumer Manager for handling user name,e-mail and MSISDN.
 @discussion If set, this object receives a didReceiveRemoteNotification:whileAppWasInState: message when the app receives a remote notification with action != 0. If action == 0 the default push manager handles the notification by presenting the warply rich offer in a webview.
 */
@property (nonatomic, weak) id <WLCustomPushHandler> customPushHanlder;

/*!
 @methodgroup Registering for Remote Notifications
 */
/*!
 @abstract Types of Remote Notification.
 @discussion This method informs the Warply service for which kind of notification
 type the applications need to receive (ex. sound or bagde only etc).
 @param types One or many UIRemoteNotificationType
 @deprecated This method has been deprecated. Use registerForRemoteNotifications instead.
 */

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types;
#pragma clang diagnostic pop
/*!
 @discussion This method informs the Warply service for which kind of notification
 type the applications need to receive (ex. sound or bagde only etc).
 */
- (void)registerForRemoteNotifications;

/*!
 @abstract Device Registered for Remote Notifications.
 @discussion This method notifies that the device is registered successfully with
 APNS for Remote Notifications and sends its token to Warply service.
 @param deviceToken The device informations in NSData format.
 */
- (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
/*!
 @abstract Device Failed to Registered for Remote Notifications.
 @discussion This method notifies that the device failed to register with APNS 
 for Remote Notifications and sends its token to Warply service.
 @param error An NSError object that encapsulates information why registration did not succeed.
 */
- (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;

/*!
 @methodgroup Mananging Received Pushes
 */
/*!
 @abstract Application Launched due to a Remote Notification.
 @discussion This method notifies the WLPushManager that application was launched
 and the pass the launch options.
 @param launchOptions A dictionary with the application launch options. May be 
 empty if application launched by user.
 */
- (void)didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
/*!
 @abstract Application Received a Remote Notification
 @discussion If the application is running and receives a remote notification, this method is called to process the remote notification.
 @param userInfo A dictionary that contains information related to the remote notification, including a badge number for the application icon, an alert sound, an alert message to display to the user, a notification identifier, and custom data.
 @param state the state that the app was in at the time it received the push notification.
 @discussion The default implementation is intented to handle warply rich push offers. That is remote push notifications that "carry" the information of an offer url (@link //apple_ref/occ/instp/WLBaseItem/session_uuid session_uuid @/link) If the notification is received when the app is closed and the user taps on the alert displayed by the iOS, the app launches and warply calls the push manager's didReceiveRemoteNotification:whileAppWasInState: method which saves the payload as a pending item to be handled later, when the root view controller's view appears by using the @link //apple_ref/occ/instp/WLPushManager/handlePendingNotification handlePendingNotification @/link method. If the notification is received when the app is in the background and the user taps on the alert on the alert displayed by the iOS , the app launches and warply calls the push manager's didReceiveRemoteNotification:whileAppWasInState: which displays the offer using the @link //apple_ref/occ/instp/WLPushManager/showItem: showItem: @/link method. If the notification is received when the app is in the foreground, no alert is being displayed by the iOS. didReceiveRemoteNotification:whileAppWasInState: displays an alert to inform the user that he has a pending remote notification and to ask if he wants to see it or ignore it.
 */
- (void)didReceiveRemoteNotification:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state;

/*!
 @abstract Application received a Remote Notification.
 @discussion This method notifies the WLPushManager that a remote notification was received and passes the data to the didReceiveRemoteNotification:whileAppWasInState: method
 @param userInfo The NSDictionary data that contains the remote notification that was received.
 */
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo;

/*!
 @methodgroup Mananging Notifications Badge
 */
/*!
 @abstract Reset notifications badge.
 @discussion This method resets the notification badge to zero.
 */
- (void)resetBadge;

/*!
 @methodgroup Handling Pending Notifications
 */
/*!
 @abstract Handles the pending notification item if it exists.
 @discussion The default implemention calls showItem: and displays modally a mini browser with the warp offer. Returns YES if a pending notification existed at the time the method was being called, otherwise returns NO.
 @seealso 
 */
- (BOOL)handlePendingNotification;

/*!
 @abstract Displays displays modally a mini browser with the warp offer.
 @param item A WLInboxItem object representation of an offer.
 */
- (void)showItem:(WLInboxItem*)item;

/*!
 @methodgroup Handling Device Information
 */
/*!
 @abstract Sends the application and device information.
 @discussion  This function is internal and only used by Warply service.
 */
- (void)sendDeviceInfoIfNecessary;

- (void)sendDeviceInfo;

- (NSDictionary *)deviceInfo;

- (NSDictionary *)applicationData;

@end

/*!
 @protocol WLCustomPushHandler
 @abstract If there is a need for custom push handling the user must create an option that conforms to the WLCustomPushHandler protocol and implement the didReceiveRemoteNotification:whileAppWasInState: method.
 */
/*!
 @methodgroup Handling Custom Push Notifications
 */
/*!
 @abstract Handles a remote notification that is not of the default warply type (action .
 @discussion The default implemention calls showItem: and displays modally a mini browser with the warp offer.
 @seealso
 */
@protocol WLCustomPushHandler <NSObject>

- (void)didReceiveRemoteNotification:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state;

@end