Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
react-native-notifications
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
冷佳娟
react-native-notifications
Commits
6c99242e
Commit
6c99242e
authored
Jul 31, 2019
by
yogevbd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Splits requestPermissionsWithCategories to two functions
parent
8099dbfc
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
356 additions
and
47 deletions
+356
-47
RNNotifications/RCTConvert+RNNotifications.m
RNNotifications/RCTConvert+RNNotifications.m
+0
-8
RNNotifications/RNBridgeModule.m
RNNotifications/RNBridgeModule.m
+6
-2
RNNotifications/RNCommandsHandler.h
RNNotifications/RNCommandsHandler.h
+3
-1
RNNotifications/RNCommandsHandler.m
RNNotifications/RNCommandsHandler.m
+6
-2
RNNotifications/RNNotificationCenter.h
RNNotifications/RNNotificationCenter.h
+3
-1
RNNotifications/RNNotificationCenter.m
RNNotifications/RNNotificationCenter.m
+13
-10
RNNotifications/RNNotificationsTests/Integration/RNCommandsHandlerIntegrationTest.m
...tionsTests/Integration/RNCommandsHandlerIntegrationTest.m
+18
-8
lib/src/Notifications.ts
lib/src/Notifications.ts
+75
-3
lib/src/adapters/NativeCommandsSender.ts
lib/src/adapters/NativeCommandsSender.ts
+56
-6
lib/src/commands/Commands.test.ts
lib/src/commands/Commands.test.ts
+110
-5
lib/src/commands/Commands.ts
lib/src/commands/Commands.ts
+41
-1
lib/src/interfaces/Notification.ts
lib/src/interfaces/Notification.ts
+25
-0
No files found.
RNNotifications/RCTConvert+RNNotifications.m
View file @
6c99242e
#import "RCTConvert+RNNotifications.h"
@implementation
RCTConvert
(
UIUserNotificationActivationMode
)
RCT_ENUM_CONVERTER
(
UIUserNotificationActivationMode
,
(@{
@"foreground"
:
@
(
UIUserNotificationActivationModeForeground
),
@"background"
:
@
(
UIUserNotificationActivationModeBackground
)
}),
UIUserNotificationActivationModeForeground
,
integerValue
)
@end
@implementation
RCTConvert
(
UNNotificationActionOptions
)
+
(
UNNotificationActionOptions
)
UNUserNotificationActionOptions
:(
id
)
json
{
...
...
RNNotifications/RNBridgeModule.m
View file @
6c99242e
...
...
@@ -32,8 +32,12 @@ RCT_EXPORT_MODULE();
#pragma mark - JS interface
RCT_EXPORT_METHOD
(
requestPermissionsWithCategories
:
(
NSArray
*
)
json
)
{
[
_commandsHandler
requestPermissionsWithCategories
:
json
];
RCT_EXPORT_METHOD
(
requestPermissions
)
{
[
_commandsHandler
requestPermissions
];
}
RCT_EXPORT_METHOD
(
setCategories
:
(
NSArray
*
)
categories
)
{
[
_commandsHandler
setCategories
:
categories
];
}
RCT_EXPORT_METHOD
(
getInitialNotification
:
(
RCTPromiseResolveBlock
)
resolve
reject
:
(
RCTPromiseRejectBlock
)
reject
)
{
...
...
RNNotifications/RNCommandsHandler.h
View file @
6c99242e
...
...
@@ -5,7 +5,9 @@
-
(
instancetype
)
init
;
-
(
void
)
requestPermissionsWithCategories
:(
NSArray
*
)
json
;
-
(
void
)
requestPermissions
;
-
(
void
)
setCategories
:(
NSArray
*
)
categories
;
-
(
void
)
getInitialNotification
:(
RCTPromiseResolveBlock
)
resolve
reject
:(
RCTPromiseRejectBlock
)
reject
;
...
...
RNNotifications/RNCommandsHandler.m
View file @
6c99242e
...
...
@@ -13,8 +13,12 @@
return
self
;
}
-
(
void
)
requestPermissionsWithCategories
:(
NSArray
*
)
json
{
[
_notificationCenter
requestPermissionsWithCategories
:
json
];
-
(
void
)
requestPermissions
{
[
_notificationCenter
requestPermissions
];
}
-
(
void
)
setCategories
:(
NSArray
*
)
categories
{
[
_notificationCenter
setCategories
:
categories
];
}
-
(
void
)
getInitialNotification
:(
RCTPromiseResolveBlock
)
resolve
reject
:(
RCTPromiseRejectBlock
)
reject
{
...
...
RNNotifications/RNNotificationCenter.h
View file @
6c99242e
...
...
@@ -10,7 +10,9 @@ typedef void (^RCTPromiseRejectBlock)(NSString *code, NSString *message, NSError
-
(
void
)
isRegisteredForRemoteNotifications
:(
RCTPromiseResolveBlock
)
resolve
;
-
(
void
)
requestPermissionsWithCategories
:(
NSArray
*
)
json
;
-
(
void
)
requestPermissions
;
-
(
void
)
setCategories
:(
NSArray
*
)
json
;
-
(
void
)
checkPermissions
:(
RCTPromiseResolveBlock
)
resolve
;
...
...
RNNotifications/RNNotificationCenter.m
View file @
6c99242e
...
...
@@ -3,16 +3,7 @@
@implementation
RNNotificationCenter
-
(
void
)
requestPermissionsWithCategories
:(
NSArray
*
)
json
{
NSMutableSet
<
UNNotificationCategory
*>*
categories
=
nil
;
if
([
json
count
]
>
0
)
{
categories
=
[
NSMutableSet
new
];
for
(
NSDictionary
*
categoryJson
in
json
)
{
[
categories
addObject
:[
RCTConvert
UNMutableUserNotificationCategory
:
categoryJson
]];
}
}
[[
UNUserNotificationCenter
currentNotificationCenter
]
setNotificationCategories
:
categories
];
-
(
void
)
requestPermissions
{
UNAuthorizationOptions
authOptions
=
(
UNAuthorizationOptionBadge
|
UNAuthorizationOptionSound
|
UNAuthorizationOptionAlert
);
[
UNUserNotificationCenter
.
currentNotificationCenter
requestAuthorizationWithOptions
:
authOptions
completionHandler
:
^
(
BOOL
granted
,
NSError
*
_Nullable
error
)
{
if
(
!
error
&&
granted
)
{
...
...
@@ -27,6 +18,18 @@
}];
}
-
(
void
)
setCategories
:(
NSArray
*
)
json
{
NSMutableSet
<
UNNotificationCategory
*>*
categories
=
nil
;
if
([
json
count
]
>
0
)
{
categories
=
[
NSMutableSet
new
];
for
(
NSDictionary
*
categoryJson
in
json
)
{
[
categories
addObject
:[
RCTConvert
UNMutableUserNotificationCategory
:
categoryJson
]];
}
}
[[
UNUserNotificationCenter
currentNotificationCenter
]
setNotificationCategories
:
categories
];
}
-
(
void
)
sendLocalNotification
:(
NSDictionary
*
)
notification
withId
:(
NSString
*
)
notificationId
{
UNNotificationRequest
*
localNotification
=
[
RCTConvert
UNNotificationRequest
:
notification
withId
:
notificationId
];
[[
UNUserNotificationCenter
currentNotificationCenter
]
addNotificationRequest
:
localNotification
withCompletionHandler
:
nil
];
...
...
RNNotifications/RNNotificationsTests/Integration/RNCommandsHandlerIntegrationTest.m
View file @
6c99242e
...
...
@@ -25,33 +25,43 @@
_notificationCenter
=
[
UNUserNotificationCenter
currentNotificationCenter
];
}
-
(
void
)
testRequestPermissionsWithCategories_userAuthorizedPermissions
{
NSArray
*
json
=
@[@{
@"identifier"
:
@"identifier"
}];
-
(
void
)
testRequestPermissions_userAuthorizedPermissions
{
UNAuthorizationOptions
authOptions
=
(
UNAuthorizationOptionBadge
|
UNAuthorizationOptionSound
|
UNAuthorizationOptionAlert
);
UNNotificationSettings
*
settings
=
[
UNNotificationSettings
new
];
[
settings
setValue
:
@
(
UNAuthorizationStatusAuthorized
)
forKey
:
@"authorizationStatus"
];
[[
_notificationCenter
expect
]
setNotificationCategories
:[
OCMArg
any
]];
[[
_notificationCenter
expect
]
requestAuthorizationWithOptions
:
authOptions
completionHandler
:[
OCMArg
invokeBlockWithArgs
:
@
(
YES
),
[
NSNull
null
],
nil
]];
[[
_notificationCenter
expect
]
getNotificationSettingsWithCompletionHandler
:[
OCMArg
invokeBlockWithArgs
:
settings
,
nil
]];
[[(
id
)[
UIApplication
sharedApplication
]
expect
]
registerForRemoteNotifications
];
[
_uut
requestPermissions
WithCategories
:
json
];
[
_uut
requestPermissions
];
[
_notificationCenter
verify
];
}
-
(
void
)
testRequestPermissionsWithCategories_userDeniedPermissions
{
NSArray
*
json
=
@[@{
@"identifier"
:
@"identifier"
}];
-
(
void
)
testRequestPermissions_userDeniedPermissions
{
UNAuthorizationOptions
authOptions
=
(
UNAuthorizationOptionBadge
|
UNAuthorizationOptionSound
|
UNAuthorizationOptionAlert
);
UNNotificationSettings
*
settings
=
[
UNNotificationSettings
new
];
[
settings
setValue
:
@
(
UNAuthorizationStatusDenied
)
forKey
:
@"authorizationStatus"
];
[[
_notificationCenter
expect
]
setNotificationCategories
:[
OCMArg
any
]];
[[
_notificationCenter
expect
]
requestAuthorizationWithOptions
:
authOptions
completionHandler
:[
OCMArg
invokeBlockWithArgs
:
@
(
YES
),
[
NSNull
null
],
nil
]];
[[
_notificationCenter
expect
]
getNotificationSettingsWithCompletionHandler
:[
OCMArg
invokeBlockWithArgs
:
settings
,
nil
]];
[[(
id
)[
UIApplication
sharedApplication
]
reject
]
registerForRemoteNotifications
];
[
_uut
requestPermissionsWithCategories
:
json
];
[
_uut
requestPermissions
];
[
_notificationCenter
verify
];
}
-
(
void
)
testSetCategories_shouldSetCategories
{
NSArray
*
json
=
@[@{
@"identifier"
:
@"categoryId"
,
@"actions"
:
@[@{
@"identifier"
:
@"actionId"
,
@"activationMode"
:
@"foreground"
}]}];
[[
_notificationCenter
expect
]
setNotificationCategories
:[
OCMArg
checkWithBlock
:
^
BOOL
(
NSMutableSet
<
UNNotificationCategory
*>*
categories
)
{
UNNotificationCategory
*
category
=
categories
.
allObjects
.
firstObject
;
UNNotificationAction
*
action
=
category
.
actions
.
firstObject
;
return
([
category
.
identifier
isEqualToString
:
@"categoryId"
]
&&
[
action
.
identifier
isEqualToString
:
@"actionId"
]
&&
action
.
options
==
UNNotificationActionOptionForeground
);
}]];
[
_uut
setCategories
:
json
];
[
_notificationCenter
verify
];
}
...
...
lib/src/Notifications.ts
View file @
6c99242e
...
...
@@ -2,7 +2,7 @@ import { NativeCommandsSender } from './adapters/NativeCommandsSender';
import
{
NativeEventsReceiver
}
from
'
./adapters/NativeEventsReceiver
'
;
import
{
Commands
}
from
'
./commands/Commands
'
;
import
{
EventsRegistry
}
from
'
./events/EventsRegistry
'
;
import
{
Notification
}
from
'
./interfaces/Notification
'
;
import
{
Notification
,
NotificationCategory
}
from
'
./interfaces/Notification
'
;
export
class
NotificationsRoot
{
private
readonly
nativeEventsReceiver
:
NativeEventsReceiver
;
...
...
@@ -22,14 +22,21 @@ export class NotificationsRoot {
/**
* Request permissions to send remote notifications - iOS only
*/
public
requestPermissions
()
:
Promise
<
any
>
{
public
requestPermissions
()
{
return
this
.
commands
.
requestPermissions
();
}
/**
* registerPushKit
*/
public
registerPushKit
()
{
return
this
.
commands
.
registerPushKit
();
}
/**
* Reset the app to a new layout
*/
public
localNotification
(
notification
:
Notification
)
:
Promise
<
any
>
{
public
localNotification
(
notification
:
Notification
)
{
return
this
.
commands
.
sendLocalNotification
(
notification
);
}
...
...
@@ -40,6 +47,71 @@ export class NotificationsRoot {
return
this
.
commands
.
getInitialNotification
();
}
/**
* setCategories
*/
public
setCategories
(
categories
:
[
NotificationCategory
?])
{
this
.
commands
.
setCategories
(
categories
);
}
/**
* getBadgesCount
*/
public
getBadgeCount
():
Promise
<
number
>
{
return
this
.
commands
.
getBadgeCount
();
}
/**
* setBadgeCount
* @param count number of the new badge count
*/
public
setBadgeCount
(
count
:
number
)
{
return
this
.
commands
.
setBadgeCount
(
count
);
}
/**
* cancelLocalNotification
*/
public
cancelLocalNotification
(
notificationId
:
string
)
{
return
this
.
commands
.
cancelLocalNotification
(
notificationId
);
}
/**
* cancelAllLocalNotifications
*/
public
cancelAllLocalNotifications
()
{
this
.
commands
.
cancelAllLocalNotifications
();
}
/**
* isRegisteredForRemoteNotifications
*/
public
isRegisteredForRemoteNotifications
():
Promise
<
any
>
{
this
.
commands
.
isRegisteredForRemoteNotifications
();
}
/**
* checkPermissions
*/
public
checkPermissions
()
{
return
this
.
commands
.
checkPermissions
();
}
/**
* removeAllDeliveredNotifications
*/
public
removeAllDeliveredNotifications
()
{
return
this
.
commands
.
removeAllDeliveredNotifications
();
}
/**
* removeDeliveredNotifications
* @param identifiers Array of notification identifiers
*/
public
removeDeliveredNotifications
(
identifiers
:
Array
<
string
>
)
{
return
this
.
commands
.
removeDeliveredNotifications
(
identifiers
);
}
/**
* Obtain the events registry instance
*/
...
...
lib/src/adapters/NativeCommandsSender.ts
View file @
6c99242e
import
{
NativeModules
}
from
'
react-native
'
;
import
{
Notification
}
from
'
../interfaces/Notification
'
;
import
{
Notification
,
NotificationCategory
,
NotificationPermissions
}
from
'
../interfaces/Notification
'
;
interface
NativeCommandsModule
{
getInitialNotification
():
Promise
<
any
>
;
localNotification
(
notification
:
Notification
,
id
:
string
):
Promise
<
Notification
>
;
requestPermissionsWithCategories
(
categories
:
any
):
Promise
<
any
>
;
abandonPermissions
():
Promise
<
any
>
;
getInitialNotification
():
Promise
<
Notification
>
;
localNotification
(
notification
:
Notification
,
id
:
string
):
void
;
requestPermissions
():
void
;
abandonPermissions
():
void
;
registerPushKit
():
void
;
getBadgeCount
():
Promise
<
number
>
;
setBadgeCount
(
count
:
number
):
void
;
cancelLocalNotification
(
notificationId
:
string
):
void
;
cancelAllLocalNotifications
():
void
;
isRegisteredForRemoteNotifications
():
Promise
<
boolean
>
;
checkPermissions
():
Promise
<
NotificationPermissions
>
;
removeDeliveredNotifications
(
identifiers
:
Array
<
string
>
):
void
;
removeAllDeliveredNotifications
():
void
;
setCategories
(
categories
:
[
NotificationCategory
?]):
void
;
}
export
class
NativeCommandsSender
{
...
...
@@ -23,10 +33,50 @@ export class NativeCommandsSender {
}
requestPermissions
()
{
return
this
.
nativeCommandsModule
.
requestPermissions
WithCategories
([]
);
return
this
.
nativeCommandsModule
.
requestPermissions
(
);
}
abandonPermissions
()
{
return
this
.
nativeCommandsModule
.
abandonPermissions
();
}
registerPushKit
()
{
return
this
.
nativeCommandsModule
.
registerPushKit
();
}
setCategories
(
categories
:
[
NotificationCategory
?])
{
this
.
nativeCommandsModule
.
setCategories
(
categories
);
}
getBadgeCount
():
Promise
<
number
>
{
return
this
.
nativeCommandsModule
.
getBadgeCount
();
}
setBadgeCount
(
count
:
number
)
{
this
.
nativeCommandsModule
.
setBadgeCount
(
count
);
}
cancelLocalNotification
(
notificationId
:
string
)
{
this
.
nativeCommandsModule
.
cancelLocalNotification
(
notificationId
);
}
cancelAllLocalNotifications
()
{
this
.
nativeCommandsModule
.
cancelAllLocalNotifications
();
}
isRegisteredForRemoteNotifications
():
Promise
<
any
>
{
return
this
.
nativeCommandsModule
.
isRegisteredForRemoteNotifications
();
}
checkPermissions
()
{
return
this
.
nativeCommandsModule
.
checkPermissions
();
}
removeAllDeliveredNotifications
()
{
return
this
.
nativeCommandsModule
.
removeAllDeliveredNotifications
();
}
removeDeliveredNotifications
(
identifiers
:
Array
<
string
>
)
{
return
this
.
nativeCommandsModule
.
removeDeliveredNotifications
(
identifiers
);
}
}
lib/src/commands/Commands.test.ts
View file @
6c99242e
...
...
@@ -3,7 +3,7 @@ import { mock, verify, instance, deepEqual, when, anything, anyString } from 'ts
import
{
Commands
}
from
'
./Commands
'
;
import
{
NativeCommandsSender
}
from
'
../adapters/NativeCommandsSender
'
;
import
{
Notification
}
from
'
../interfaces/Notification
'
;
import
{
Notification
,
NotificationCategory
,
NotificationPermissions
}
from
'
../interfaces/Notification
'
;
describe
(
'
Commands
'
,
()
=>
{
let
uut
:
Commands
;
...
...
@@ -18,7 +18,7 @@ describe('Commands', () => {
});
describe
(
'
getInitialNotification
'
,
()
=>
{
it
(
'
sends
getInitialNotification
to native
'
,
()
=>
{
it
(
'
sends to native
'
,
()
=>
{
uut
.
getInitialNotification
();
verify
(
mockedNativeCommandsSender
.
getInitialNotification
()).
called
();
});
...
...
@@ -33,24 +33,129 @@ describe('Commands', () => {
});
describe
(
'
requestPermissions
'
,
()
=>
{
it
(
'
sends
requestPermissions
to native
'
,
()
=>
{
it
(
'
sends to native
'
,
()
=>
{
uut
.
requestPermissions
();
verify
(
mockedNativeCommandsSender
.
requestPermissions
()).
called
();
});
});
describe
(
'
registerPushKit
'
,
()
=>
{
it
(
'
sends to native
'
,
()
=>
{
uut
.
registerPushKit
();
verify
(
mockedNativeCommandsSender
.
registerPushKit
()).
called
();
});
});
describe
(
'
setCategories
'
,
()
=>
{
it
(
'
sends to native
'
,
()
=>
{
const
emptyCategoriesArray
:
[
NotificationCategory
?]
=
[];
uut
.
setCategories
(
emptyCategoriesArray
);
verify
(
mockedNativeCommandsSender
.
setCategories
(
emptyCategoriesArray
)).
called
();
});
it
(
'
sends to native with categories
'
,
()
=>
{
const
category
:
NotificationCategory
=
{
identifier
:
'
id
'
,
actions
:
[]};
const
categoriesArray
:
[
NotificationCategory
]
=
[
category
];
uut
.
setCategories
(
categoriesArray
);
verify
(
mockedNativeCommandsSender
.
setCategories
(
categoriesArray
)).
called
();
});
});
describe
(
'
abandonPermissions
'
,
()
=>
{
it
(
'
sends
abandonPermissions
to native
'
,
()
=>
{
it
(
'
sends to native
'
,
()
=>
{
uut
.
abandonPermissions
();
verify
(
mockedNativeCommandsSender
.
abandonPermissions
()).
called
();
});
});
describe
(
'
sendLocalNotification
'
,
()
=>
{
it
(
'
sends
sendLocalNotification
to native
'
,
()
=>
{
it
(
'
sends to native
'
,
()
=>
{
const
notification
:
Notification
=
{
data
:
{},
alert
:
'
alert
'
};
uut
.
sendLocalNotification
(
notification
);
verify
(
mockedNativeCommandsSender
.
sendLocalNotification
(
notification
,
'
id
'
)).
called
();
});
});
describe
(
'
getBadgeCount
'
,
()
=>
{
it
(
'
sends to native
'
,
()
=>
{
uut
.
getBadgeCount
();
verify
(
mockedNativeCommandsSender
.
getBadgeCount
()).
called
();
});
});
describe
(
'
setBadgeCount
'
,
()
=>
{
it
(
'
sends to native
'
,
()
=>
{
uut
.
setBadgeCount
(
10
);
verify
(
mockedNativeCommandsSender
.
setBadgeCount
(
10
)).
called
();
});
});
describe
(
'
cancelLocalNotification
'
,
()
=>
{
it
(
'
sends to native
'
,
()
=>
{
uut
.
cancelLocalNotification
(
"
notificationId
"
);
verify
(
mockedNativeCommandsSender
.
cancelLocalNotification
(
"
notificationId
"
)).
called
();
});
});
describe
(
'
cancelAllLocalNotifications
'
,
()
=>
{
it
(
'
sends to native
'
,
()
=>
{
uut
.
cancelAllLocalNotifications
();
verify
(
mockedNativeCommandsSender
.
cancelAllLocalNotifications
()).
called
();
});
});
describe
(
'
isRegisteredForRemoteNotifications
'
,
()
=>
{
it
(
'
sends to native
'
,
()
=>
{
uut
.
isRegisteredForRemoteNotifications
();
verify
(
mockedNativeCommandsSender
.
isRegisteredForRemoteNotifications
()).
called
();
});
it
(
'
return positive response from native
'
,
async
()
=>
{
when
(
mockedNativeCommandsSender
.
isRegisteredForRemoteNotifications
()).
thenResolve
(
true
);
const
isRegistered
=
await
uut
.
isRegisteredForRemoteNotifications
();
verify
(
mockedNativeCommandsSender
.
isRegisteredForRemoteNotifications
()).
called
();
expect
(
isRegistered
).
toEqual
(
true
);
});
it
(
'
return negative response from native
'
,
async
()
=>
{
when
(
mockedNativeCommandsSender
.
isRegisteredForRemoteNotifications
()).
thenResolve
(
false
);
const
isRegistered
=
await
uut
.
isRegisteredForRemoteNotifications
();
expect
(
isRegistered
).
toEqual
(
false
);
});
});
describe
(
'
checkPermissions
'
,
()
=>
{
it
(
'
sends to native
'
,
()
=>
{
uut
.
checkPermissions
();
verify
(
mockedNativeCommandsSender
.
checkPermissions
()).
called
();
});
it
(
'
return negative response from native
'
,
async
()
=>
{
const
expectedPermissions
:
NotificationPermissions
=
{
badge
:
false
,
alert
:
true
,
sound
:
false
};
when
(
mockedNativeCommandsSender
.
checkPermissions
()).
thenResolve
(
expectedPermissions
);
const
permissions
=
await
uut
.
checkPermissions
();
expect
(
permissions
).
toEqual
(
expectedPermissions
);
});
});
describe
(
'
removeAllDeliveredNotifications
'
,
()
=>
{
it
(
'
sends to native
'
,
()
=>
{
uut
.
removeAllDeliveredNotifications
();
verify
(
mockedNativeCommandsSender
.
removeAllDeliveredNotifications
()).
called
();
});
});
describe
(
'
removeDeliveredNotifications
'
,
async
()
=>
{
it
(
'
sends to native
'
,
()
=>
{
const
identifiers
:
Array
<
string
>
=
[
"
id1
"
,
"
id2
"
];
uut
.
removeDeliveredNotifications
(
identifiers
);
verify
(
mockedNativeCommandsSender
.
removeDeliveredNotifications
(
identifiers
)).
called
();
});
});
});
lib/src/commands/Commands.ts
View file @
6c99242e
import
*
as
_
from
'
lodash
'
;
import
{
NativeCommandsSender
}
from
'
../adapters/NativeCommandsSender
'
;
import
{
Notification
}
from
'
../interfaces/Notification
'
;
import
{
Notification
,
NotificationCategory
,
NotificationPermissions
}
from
'
../interfaces/Notification
'
;
export
class
Commands
{
constructor
(
...
...
@@ -27,4 +27,44 @@ export class Commands {
const
result
=
this
.
nativeCommandsSender
.
abandonPermissions
();
return
result
;
}
public
registerPushKit
()
{
this
.
nativeCommandsSender
.
registerPushKit
();
}
public
setCategories
(
categories
:
[
NotificationCategory
?])
{
this
.
nativeCommandsSender
.
setCategories
(
categories
);
}
public
getBadgeCount
():
Promise
<
number
>
{
return
this
.
nativeCommandsSender
.
getBadgeCount
();
}
public
setBadgeCount
(
count
:
number
)
{
this
.
nativeCommandsSender
.
setBadgeCount
(
count
);
}
public
cancelLocalNotification
(
notificationId
:
string
)
{
this
.
nativeCommandsSender
.
cancelLocalNotification
(
notificationId
);
}
public
cancelAllLocalNotifications
()
{
this
.
nativeCommandsSender
.
cancelAllLocalNotifications
();
}
public
isRegisteredForRemoteNotifications
():
Promise
<
boolean
>
{
return
this
.
nativeCommandsSender
.
isRegisteredForRemoteNotifications
();
}
public
checkPermissions
():
Promise
<
NotificationPermissions
>
{
return
this
.
nativeCommandsSender
.
checkPermissions
();
}
public
removeAllDeliveredNotifications
()
{
this
.
nativeCommandsSender
.
removeAllDeliveredNotifications
();
}
public
removeDeliveredNotifications
(
identifiers
:
Array
<
string
>
)
{
return
this
.
nativeCommandsSender
.
removeDeliveredNotifications
(
identifiers
);
}
}
lib/src/interfaces/Notification.ts
View file @
6c99242e
...
...
@@ -6,3 +6,28 @@ export interface Notification {
type
?:
string
;
thread
?:
string
;
}
export
interface
NotificationPermissions
{
badge
:
boolean
;
alert
:
boolean
;
sound
:
boolean
;
}
export
interface
NotificationCategory
{
identifier
:
string
actions
:
[
NotificationAction
?];
}
export
interface
NotificationTextInput
{
buttonTitle
:
string
;
placeholder
:
string
;
}
export
interface
NotificationAction
{
identifier
:
string
;
activationMode
:
'
foreground
'
|
'
authenticationRequired
'
|
'
destructive
'
;
title
:
string
;
authenticationRequired
:
boolean
;
textInput
:
NotificationTextInput
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment