-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy pathOSNotificationsManager.h
More file actions
144 lines (113 loc) · 7.03 KB
/
OSNotificationsManager.h
File metadata and controls
144 lines (113 loc) · 7.03 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
/*
Modified MIT License
Copyright 2022 OneSignal
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
1. The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
2. All copies of substantial portions of the Software may only be used in connection
with services provided by OneSignal.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#import <Foundation/Foundation.h>
#import <OneSignalNotifications/OneSignalNotificationSettings.h>
#import <OneSignalNotifications/OSPermission.h>
#import <OneSignalCore/OneSignalCore.h>
#import <UIKit/UIKit.h>
#import <OneSignalNotifications/OSNotification+OneSignal.h>
@protocol OSNotificationClickListener <NSObject>
- (void)onClickNotification:(OSNotificationClickEvent *_Nonnull)event
NS_SWIFT_NAME(onClick(event:));
@end
@interface OSNotificationWillDisplayEvent : NSObject
@property (readonly, strong, nonatomic, nonnull) OSDisplayableNotification *notification; // TODO: strong? nonatomic? nullable?
- (void)preventDefault;
@end
@protocol OSNotificationLifecycleListener <NSObject>
- (void)onWillDisplayNotification:(OSNotificationWillDisplayEvent *_Nonnull)event NS_SWIFT_NAME(onWillDisplay(event:));
@end
/**
Public API for the Notifications namespace.
*/
@protocol OSNotifications <NSObject>
+ (BOOL)permission NS_REFINED_FOR_SWIFT;
+ (BOOL)canRequestPermission NS_REFINED_FOR_SWIFT;
+ (OSNotificationPermission)permissionNative NS_REFINED_FOR_SWIFT;
+ (void)addForegroundLifecycleListener:(NSObject<OSNotificationLifecycleListener> *_Nullable)listener;
+ (void)removeForegroundLifecycleListener:(NSObject<OSNotificationLifecycleListener> *_Nullable)listener;
+ (void)addClickListener:(NSObject<OSNotificationClickListener>*_Nonnull)listener NS_REFINED_FOR_SWIFT;
+ (void)removeClickListener:(NSObject<OSNotificationClickListener>*_Nonnull)listener NS_REFINED_FOR_SWIFT;
+ (void)requestPermission:(OSUserResponseBlock _Nullable )block;
+ (void)requestPermission:(OSUserResponseBlock _Nullable )block fallbackToSettings:(BOOL)fallback;
+ (void)registerForProvisionalAuthorization:(OSUserResponseBlock _Nullable )block NS_REFINED_FOR_SWIFT;
+ (void)addPermissionObserver:(NSObject<OSNotificationPermissionObserver>*_Nonnull)observer NS_REFINED_FOR_SWIFT;
+ (void)removePermissionObserver:(NSObject<OSNotificationPermissionObserver>*_Nonnull)observer NS_REFINED_FOR_SWIFT;
+ (void)clearAll;
// Manual integration APIs (for use when swizzling is disabled via Info.plist)
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *_Nonnull)deviceToken
NS_SWIFT_NAME(didRegisterForRemoteNotifications(deviceToken:));
+ (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *_Nonnull)error
NS_SWIFT_NAME(didFailToRegisterForRemoteNotifications(error:));
+ (void)didReceiveRemoteNotification:(NSDictionary *_Nonnull)userInfo completionHandler:(void (^_Nonnull)(UIBackgroundFetchResult))completionHandler
NS_SWIFT_NAME(didReceiveRemoteNotification(userInfo:completionHandler:));
+ (void)willPresentNotificationWithPayload:(NSDictionary *_Nonnull)payload completion:(OSNotificationDisplayResponse _Nonnull)completion
NS_SWIFT_NAME(willPresentNotification(payload:completion:));
+ (void)didReceiveNotificationResponse:(UNNotificationResponse *_Nonnull)response
NS_SWIFT_NAME(didReceiveNotificationResponse(_:));
+ (void)setBadgeCount:(NSInteger)badgeCount;
@end
@protocol OneSignalNotificationsDelegate <NSObject>
// set delegate before user
// can check responds to selector
- (void)setNotificationTypes:(int)notificationTypes;
- (void)setPushToken:(NSString * _Nonnull)pushToken;
@end
@interface OSNotificationsManager : NSObject <OSNotifications>
@property (class, weak, nonatomic, nullable) id<OneSignalNotificationsDelegate> delegate;
+ (Class<OSNotifications> _Nonnull)Notifications;
+ (void)startSwizzling;
+ (void)setColdStartFromTapOnNotification:(BOOL)coldStartFromTapOnNotification;
+ (BOOL)getColdStartFromTapOnNotification;
@property (class, readonly) OSPermissionStateInternal* _Nonnull currentPermissionState;
@property (class) OSPermissionStateInternal* _Nonnull lastPermissionState;
+ (void)clearStatics; // Used by Unit Tests
// Indicates if the app provides its own custom Notification customization settings UI
// To enable this, set kOSSettingsKeyProvidesAppNotificationSettings to true in init.
+ (BOOL)providesAppNotificationSettings;
/* Used to determine if the app is able to present it's own customized Notification Settings view (iOS 12+) */
+ (void)setProvidesNotificationSettingsView:(BOOL)providesView;
+ (BOOL)registerForAPNsToken;
+ (void)sendPushTokenToDelegate;
+ (int)getNotificationTypes:(BOOL)pushDisabled;
+ (void)updateNotificationTypes:(int)notificationTypes;
+ (void)sendNotificationTypesUpdateToDelegate;
// Used to manage observers added by the app developer.
@property (class, readonly) ObservablePermissionStateChangesType* _Nullable permissionStateChangesObserver;
@property (class, readonly) OneSignalNotificationSettings* _Nonnull osNotificationSettings;
// This is set by the user module
+ (void)setPushSubscriptionId:(NSString *_Nullable)pushSubscriptionId;
+ (void)handleWillShowInForegroundForNotification:(OSNotification *_Nonnull)notification completion:(OSNotificationDisplayResponse _Nonnull)completion;
+ (void)handleNotificationActionWithUrl:(NSString* _Nullable)url actionID:(NSString* _Nonnull)actionID;
+ (void)clearBadgeCount:(BOOL)fromNotifOpened fromClearAll:(BOOL)fromClearAll;
+ (void)notificationReceived:(NSDictionary* _Nonnull)messageDict wasOpened:(BOOL)opened;
+ (void)checkProvisionalAuthorizationStatus;
+ (void)registerLifecycleObserver;
+ (BOOL)isSwizzlingDisabled;
// Internal entry points called by swizzled delegate paths
// These bypass the swizzling-active guard so the SDK doesn't block its own calls
+ (void)processRegisteredDeviceToken:(NSData *_Nonnull)deviceToken;
+ (void)processFailedRemoteNotificationsRegistration:(NSError *_Nonnull)error;
+ (BOOL)processReceivedRemoteNotification:(NSDictionary *_Nonnull)userInfo completionHandler:(void (^_Nonnull)(UIBackgroundFetchResult))completionHandler;
+ (void)processWillPresentNotificationWithPayload:(NSDictionary *_Nonnull)payload completion:(OSNotificationDisplayResponse _Nonnull)completion;
+ (void)processNotificationResponse:(UNNotificationResponse *_Nonnull)response;
@end