|
| 1 | +/** |
| 2 | + * Modified MIT License |
| 3 | + * |
| 4 | + * Copyright 2016 OneSignal |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * 1. The above copyright notice and this permission notice shall be included in |
| 14 | + * all copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * 2. All copies of substantial portions of the Software may only be used in connection |
| 17 | + * with services provided by OneSignal. |
| 18 | + * |
| 19 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 20 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 22 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 23 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 24 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 25 | + * THE SOFTWARE. |
| 26 | + */ |
| 27 | + |
| 28 | +/*** |
| 29 | + |
| 30 | + ### Setting up the SDK ### |
| 31 | + Follow the documentation from https://documentation.onesignal.com/docs/installing-the-onesignal-ios-sdk to setup OneSignal in your app. |
| 32 | + |
| 33 | + ### API Reference ### |
| 34 | + Follow the documentation from https://documentation.onesignal.com/docs/ios-sdk-api for a detailed explanation of the API. |
| 35 | + |
| 36 | + ### FAQ & Troubleshoot ### |
| 37 | + FAQ: https://documentation.onesignal.com/docs/frequently-asked-questions-1 |
| 38 | + Troubleshoot: https://documentation.onesignal.com/docs/common-problems-1 |
| 39 | + |
| 40 | + For help on how to upgrade your code from 1.* SDK to 2.*: https://documentation.onesignal.com/docs/upgrading-to-sdk-20 |
| 41 | + |
| 42 | + ### More ### |
| 43 | + iOS Configuration: https://documentation.onesignal.com/docs/generating-an-ios-push-certificate |
| 44 | + REST API: https://documentation.onesignal.com/docs/server-api-overview |
| 45 | + Create Notification API: https://documentation.onesignal.com/docs/notifications-create-notification |
| 46 | + |
| 47 | +***/ |
| 48 | + |
| 49 | +#import <Foundation/Foundation.h> |
| 50 | + |
| 51 | +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 |
| 52 | +#define XC8_AVAILABLE 1 |
| 53 | +#import <UserNotifications/UserNotifications.h> |
| 54 | + |
| 55 | +@protocol OSUserNotificationCenterDelegate <NSObject> |
| 56 | +@optional |
| 57 | +- (void)userNotificationCenter:(id)center willPresentNotification:(id)notification withCompletionHandler:(void (^)(NSUInteger options))completionHandler; |
| 58 | +- (void)userNotificationCenter:(id)center didReceiveNotificationResponse:(id)response withCompletionHandler:(void (^)())completionHandler; |
| 59 | +@end |
| 60 | + |
| 61 | +#endif |
| 62 | + |
| 63 | +/* The action type associated to an OSNotificationAction object */ |
| 64 | +typedef enum : NSUInteger { |
| 65 | + Opened, |
| 66 | + ActionTaken |
| 67 | +} OSNotificationActionType; |
| 68 | + |
| 69 | +/* The way a notification was displayed to the user */ |
| 70 | +typedef enum : NSUInteger { |
| 71 | + /*iOS native notification display*/ |
| 72 | + Notification, |
| 73 | + |
| 74 | + /*Default UIAlertView display*/ |
| 75 | + InAppAlert, |
| 76 | + |
| 77 | + /*Notification is silent, or app is in focus but InAppAlertNotifications are disabled*/ |
| 78 | + None |
| 79 | +} OSNotificationDisplayType; |
| 80 | + |
| 81 | +@interface OSNotificationAction : NSObject |
| 82 | + |
| 83 | +/* The type of the notification action */ |
| 84 | +@property(readonly)OSNotificationActionType type; |
| 85 | + |
| 86 | +/* The ID associated with the button tapped. NULL when the actionType is NotificationTapped or InAppAlertClosed */ |
| 87 | +@property(readonly)NSString* actionID; |
| 88 | + |
| 89 | +@end |
| 90 | + |
| 91 | +@interface OSNotificationPayload : NSObject |
| 92 | + |
| 93 | +/* Unique Message Identifier */ |
| 94 | +@property(readonly)NSString* notificationID; |
| 95 | + |
| 96 | +/* Provide this key with a value of 1 to indicate that new content is available. |
| 97 | + Including this key and value means that when your app is launched in the background or resumed application:didReceiveRemoteNotification:fetchCompletionHandler: is called. */ |
| 98 | +@property(readonly)BOOL contentAvailable; |
| 99 | + |
| 100 | +/* The badge assigned to the application icon */ |
| 101 | +@property(readonly)NSUInteger badge; |
| 102 | + |
| 103 | +/* The sound parameter passed to the notification |
| 104 | + By default set to UILocalNotificationDefaultSoundName */ |
| 105 | +@property(readonly)NSString* sound; |
| 106 | + |
| 107 | +/* Main push content */ |
| 108 | +@property(readonly)NSString* title; |
| 109 | +@property(readonly)NSString* subtitle; |
| 110 | +@property(readonly)NSString* body; |
| 111 | + |
| 112 | +/* Web address to launch within the app via a UIWebView */ |
| 113 | +@property(readonly)NSString* launchURL; |
| 114 | + |
| 115 | +/* Additional key value properties set within the payload */ |
| 116 | +@property(readonly)NSDictionary* additionalData; |
| 117 | + |
| 118 | +/* iOS 10+ : Attachments sent as part of the rich notification */ |
| 119 | +@property(readonly)NSDictionary* attachments; |
| 120 | + |
| 121 | +/* Action buttons passed */ |
| 122 | +@property(readonly)NSDictionary *actionButtons; |
| 123 | + |
| 124 | +/* Holds the original payload received |
| 125 | + Keep the raw value for users that would like to root the push */ |
| 126 | +@property(readonly)NSDictionary *rawPayload; |
| 127 | + |
| 128 | +@end |
| 129 | + |
| 130 | +@interface OSNotification : NSObject |
| 131 | + |
| 132 | +/* Notification Payload */ |
| 133 | +@property(readonly)OSNotificationPayload* payload; |
| 134 | + |
| 135 | +/* Display method of the notification */ |
| 136 | +@property(readonly)OSNotificationDisplayType displayType; |
| 137 | + |
| 138 | +/* Set to true when the user was able to see the notification and reacted to it |
| 139 | + Set to false when app is in focus and in-app alerts are disabled, or the remote notification is silent. */ |
| 140 | +@property(readonly, getter=wasShown)BOOL shown; |
| 141 | + |
| 142 | +/* Set to true when the received notification is silent |
| 143 | + Silent means there is no alert, sound, or badge payload in the aps dictionary |
| 144 | + requires remote-notification within UIBackgroundModes array of the Info.plist */ |
| 145 | +@property(readonly, getter=isSilentNotification)BOOL silentNotification; |
| 146 | + |
| 147 | +/* iOS 10+: Indicates wether or not the received notification has mutableContent : 1 assigned to its payload |
| 148 | + Used for UNNotificationServiceExtension to launch extension. |
| 149 | +*/ |
| 150 | +#if XC8_AVAILABLE |
| 151 | +@property(readonly, getter=hasMutableContent)BOOL mutableContent; |
| 152 | +#endif |
| 153 | + |
| 154 | +/* Convert object into an NSString that can be convertible into a custom Dictionary / JSON Object */ |
| 155 | +- (NSString*)stringify; |
| 156 | + |
| 157 | +@end |
| 158 | + |
| 159 | + |
| 160 | +@interface OSNotificationOpenedResult : NSObject |
| 161 | + |
| 162 | +@property(readonly)OSNotification* notification; |
| 163 | + |
| 164 | +@property(readonly)OSNotificationAction *action; |
| 165 | + |
| 166 | +/* Convert object into an NSString that can be convertible into a custom Dictionary / JSON Object */ |
| 167 | +- (NSString*)stringify; |
| 168 | + |
| 169 | +@end; |
| 170 | + |
| 171 | +typedef void (^OSResultSuccessBlock)(NSDictionary* result); |
| 172 | +typedef void (^OSFailureBlock)(NSError* error); |
| 173 | + |
| 174 | +/*Block for notifying avalability of the User's ID and push token*/ |
| 175 | +typedef void (^OSIdsAvailableBlock)(NSString* userId, NSString* pushToken); |
| 176 | + |
| 177 | +/*Block for handling the reception of a remote notification */ |
| 178 | +typedef void (^OSHandleNotificationReceivedBlock)(OSNotification* notification); |
| 179 | + |
| 180 | +/*Block for handling a user reaction to a notification*/ |
| 181 | +typedef void (^OSHandleNotificationActionBlock)(OSNotificationOpenedResult * result); |
| 182 | + |
| 183 | +/*Dictionary of keys to pass alongside the init serttings*/ |
| 184 | + |
| 185 | +/*Let OneSignal directly promt for push notifications on init*/ |
| 186 | +extern NSString * const kOSSettingsKeyAutoPrompt; |
| 187 | + |
| 188 | +/*Enable the default in-app alerts*/ |
| 189 | +extern NSString * const kOSSettingsKeyInAppAlerts; |
| 190 | + |
| 191 | +/*Enable In-App display of Launch URLs*/ |
| 192 | +extern NSString * const kOSSettingsKeyInAppLaunchURL; |
| 193 | + |
| 194 | +/** |
| 195 | + OneSignal provides a high level interface to interact with OneSignal's push service. |
| 196 | + OneSignal is a singleton for applications which use a globally available client to share configuration settings. |
| 197 | + You should avoid creating instances of this class at all costs. Instead, access its instance methods. |
| 198 | + Include `#import <OneSignal/OneSignal.h>` in your application files to access OneSignal's methods. |
| 199 | + **/ |
| 200 | +@interface OneSignal : NSObject |
| 201 | + |
| 202 | +extern NSString* const ONESIGNAL_VERSION; |
| 203 | + |
| 204 | +typedef NS_ENUM(NSUInteger, ONE_S_LOG_LEVEL) { |
| 205 | + ONE_S_LL_NONE, ONE_S_LL_FATAL, ONE_S_LL_ERROR, ONE_S_LL_WARN, ONE_S_LL_INFO, ONE_S_LL_DEBUG, ONE_S_LL_VERBOSE |
| 206 | +}; |
| 207 | + |
| 208 | +///-------------------- |
| 209 | +/// @name Initialize` |
| 210 | +///-------------------- |
| 211 | + |
| 212 | +/** |
| 213 | + Initialize OneSignal. Sends push token to OneSignal so you can later send notifications. |
| 214 | + |
| 215 | +*/ |
| 216 | + |
| 217 | +// - Initialization |
| 218 | ++ (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId; |
| 219 | ++ (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId handleNotificationAction:(OSHandleNotificationActionBlock)actionCallback; |
| 220 | ++ (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId handleNotificationAction:(OSHandleNotificationActionBlock)actionCallback settings:(NSDictionary*)settings; |
| 221 | ++ (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId handleNotificationReceived:(OSHandleNotificationReceivedBlock)receivedCallback handleNotificationAction:(OSHandleNotificationActionBlock)actionCallback settings:(NSDictionary*)settings; |
| 222 | + |
| 223 | ++ (NSString*)app_id; |
| 224 | + |
| 225 | +// Only use if you passed FALSE to autoRegister |
| 226 | ++ (void)registerForPushNotifications; |
| 227 | + |
| 228 | +// - Logging |
| 229 | ++ (void)setLogLevel:(ONE_S_LOG_LEVEL)logLevel visualLevel:(ONE_S_LOG_LEVEL)visualLogLevel; |
| 230 | ++ (void) onesignal_Log:(ONE_S_LOG_LEVEL)logLevel message:(NSString*)message; |
| 231 | + |
| 232 | +// - Tagging |
| 233 | ++ (void)sendTag:(NSString*)key value:(NSString*)value onSuccess:(OSResultSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock; |
| 234 | ++ (void)sendTag:(NSString*)key value:(NSString*)value; |
| 235 | ++ (void)sendTags:(NSDictionary*)keyValuePair onSuccess:(OSResultSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock; |
| 236 | ++ (void)sendTags:(NSDictionary*)keyValuePair; |
| 237 | ++ (void)sendTagsWithJsonString:(NSString*)jsonString; |
| 238 | ++ (void)getTags:(OSResultSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock; |
| 239 | ++ (void)getTags:(OSResultSuccessBlock)successBlock; |
| 240 | ++ (void)deleteTag:(NSString*)key onSuccess:(OSResultSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock; |
| 241 | ++ (void)deleteTag:(NSString*)key; |
| 242 | ++ (void)deleteTags:(NSArray*)keys onSuccess:(OSResultSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock; |
| 243 | ++ (void)deleteTags:(NSArray*)keys; |
| 244 | ++ (void)deleteTagsWithJsonString:(NSString*)jsonString; |
| 245 | + |
| 246 | +// - Get user ID & Push Token |
| 247 | ++ (void)IdsAvailable:(OSIdsAvailableBlock)idsAvailableBlock; |
| 248 | + |
| 249 | +// - Alerting |
| 250 | ++ (void)setSubscription:(BOOL)enable; |
| 251 | + |
| 252 | +// - Posting Notification |
| 253 | ++ (void)postNotification:(NSDictionary*)jsonData; |
| 254 | ++ (void)postNotification:(NSDictionary*)jsonData onSuccess:(OSResultSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock; |
| 255 | ++ (void)postNotificationWithJsonString:(NSString*)jsonData onSuccess:(OSResultSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock; |
| 256 | + |
| 257 | +// - Request and track user's location |
| 258 | ++ (void)promptLocation; |
| 259 | + |
| 260 | +// - Sends the MD5 and SHA1 of the provided email |
| 261 | +// Optional method that sends us the user's email as an anonymized hash so that we can better target and personalize notifications sent to that user across their devices. |
| 262 | ++ (void)syncHashedEmail:(NSString*)email; |
| 263 | + |
| 264 | +// - iOS 10 BETA features currently only available on XCode 8 & iOS 10.0+ |
| 265 | +#if XC8_AVAILABLE |
| 266 | ++ (void)setNotificationCenterDelegate:(id<OSUserNotificationCenterDelegate>)delegate; |
| 267 | ++ (id<OSUserNotificationCenterDelegate>)notificationCenterDelegate; |
| 268 | +#endif |
| 269 | + |
| 270 | +@end |
0 commit comments