WLPushManager.h
10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
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