Skip to content

Commit bdb8953

Browse files
committed
Adding functions to the Notifications namespace
1 parent 243379b commit bdb8953

File tree

4 files changed

+483
-3
lines changed

4 files changed

+483
-3
lines changed

ios/Classes/OSFlutterNotifications.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
5353
[self clearAll:call withResult:result];
5454
else if ([@"OneSignal#requestPermission" isEqualToString:call.method])
5555
[self requestPermission:call withResult:result];
56+
else if ([@"OneSignal#registerForProvisionalAuthorization" isEqualToString:call.method])
57+
[self registerForProvisionalAuthorization:call withResult:result];
58+
else if ([@"OneSignal#initNotificationOpenedHandlerParams" isEqualToString:call.method])
59+
[self initNotificationOpenedHandlerParams];
5660
else
5761
result(FlutterMethodNotImplemented);
5862
}
@@ -70,6 +74,12 @@ - (void)requestPermission:(FlutterMethodCall *)call withResult:(FlutterResult)re
7074
} fallbackToSettings:fallbackToSettings];
7175
}
7276

77+
- (void)registerForProvisionalAuthorization:(FlutterMethodCall *)call withResult:(FlutterResult)result {
78+
[OneSignal.Notifications registerForProvisionalAuthorization:^(BOOL accepted) {
79+
result(@(accepted));
80+
}];
81+
}
82+
7383
- (void)onOSPermissionChanged:(OSPermissionState*)state {
7484
// Example of detecting the curret permission
7585
if (state.reachable == true) {
@@ -81,5 +91,16 @@ - (void)onOSPermissionChanged:(OSPermissionState*)state {
8191
NSLog(@"PermissionState:\n%@", state);
8292
}
8393

94+
- (void)initNotificationOpenedHandlerParams {
95+
[OneSignal.Notifications setNotificationOpenedHandler:^(OSNotificationOpenedResult * _Nonnull result) {
96+
[self handleNotificationOpened:result];
97+
}];
98+
}
99+
100+
#pragma mark Opened Notification Handlers
101+
- (void)handleNotificationOpened:(OSNotificationOpenedResult *)result {
102+
[self.channel invokeMethod:@"OneSignal#handleOpenedNotification" arguments:result.toJson];
103+
}
104+
84105

85106
@end

0 commit comments

Comments
 (0)