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
77bce6a6
Commit
77bce6a6
authored
Aug 15, 2017
by
Ran Greenberg
Committed by
GitHub
Aug 15, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #95 from reberhardt7/master
Add iOS checkPermissions
parents
9dbc7268
24eee3b5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
2 deletions
+39
-2
README.md
README.md
+10
-0
RNNotifications/RNNotifications.m
RNNotifications/RNNotifications.m
+10
-0
index.ios.js
index.ios.js
+4
-0
test/index.ios.spec.js
test/index.ios.spec.js
+15
-2
No files found.
README.md
View file @
77bce6a6
...
...
@@ -185,6 +185,16 @@ class App extends Component {
When you have the device token, POST it to your server and register the device in your notifications provider (Amazon SNS, Azure, etc.).
You can check if the user granted permissions by calling `checkPermissions()`
:
```
javascript
NotificationsIOS.checkPermissions().then((currentPermissions) => {
console.log('Badges enabled
:
'
+
!!currentPermissions.badge);
console.log('
Sounds enabled
:
'
+
!!currentPermissions.sound);
console.log('
Alerts enabled
:
'
+
!!currentPermissions.alert);
});
```
###
Android
The
React-Native
code
equivalent
on
Android
is:
...
...
RNNotifications/RNNotifications.m
View file @
77bce6a6
...
...
@@ -562,4 +562,14 @@ RCT_EXPORT_METHOD(isRegisteredForRemoteNotifications:(RCTPromiseResolveBlock)res
resolve
(
@
(
ans
));
}
RCT_EXPORT_METHOD
(
checkPermissions
:
(
RCTPromiseResolveBlock
)
resolve
reject
:
(
RCTPromiseRejectBlock
)
reject
)
{
UIUserNotificationSettings
*
currentSettings
=
[[
UIApplication
sharedApplication
]
currentUserNotificationSettings
];
resolve
(@{
@"badge"
:
@
((
currentSettings
.
types
&
UIUserNotificationTypeBadge
)
>
0
),
@"sound"
:
@
((
currentSettings
.
types
&
UIUserNotificationTypeSound
)
>
0
),
@"alert"
:
@
((
currentSettings
.
types
&
UIUserNotificationTypeAlert
)
>
0
),
});
}
@end
index.ios.js
View file @
77bce6a6
...
...
@@ -212,4 +212,8 @@ export default class NotificationsIOS {
static
isRegisteredForRemoteNotifications
()
{
return
NativeRNNotifications
.
isRegisteredForRemoteNotifications
();
}
static
checkPermissions
()
{
return
NativeRNNotifications
.
checkPermissions
();
}
}
test/index.ios.spec.js
View file @
77bce6a6
...
...
@@ -29,7 +29,8 @@ describe("NotificationsIOS", () => {
nativeCancelLocalNotification
,
nativeCancelAllLocalNotifications
,
nativeSetBadgesCount
,
nativeIsRegisteredForRemoteNotifications
;
nativeIsRegisteredForRemoteNotifications
,
nativeCheckPermissions
;
let
NotificationsIOS
,
NotificationAction
,
NotificationCategory
;
let
someHandler
=
()
=>
{};
...
...
@@ -51,6 +52,7 @@ describe("NotificationsIOS", () => {
nativeCancelAllLocalNotifications
=
sinon
.
spy
();
nativeSetBadgesCount
=
sinon
.
spy
();
nativeIsRegisteredForRemoteNotifications
=
sinon
.
spy
();
nativeCheckPermissions
=
sinon
.
spy
();
let
libUnderTest
=
proxyquire
(
"
../index.ios
"
,
{
"
uuid
"
:
{
...
...
@@ -68,7 +70,8 @@ describe("NotificationsIOS", () => {
cancelLocalNotification
:
nativeCancelLocalNotification
,
cancelAllLocalNotifications
:
nativeCancelAllLocalNotifications
,
setBadgesCount
:
nativeSetBadgesCount
,
isRegisteredForRemoteNotifications
:
nativeIsRegisteredForRemoteNotifications
isRegisteredForRemoteNotifications
:
nativeIsRegisteredForRemoteNotifications
,
checkPermissions
:
nativeCheckPermissions
}
},
NativeAppEventEmitter
:
{
...
...
@@ -108,6 +111,7 @@ describe("NotificationsIOS", () => {
nativeCancelLocalNotification
.
reset
();
nativeCancelAllLocalNotifications
.
reset
();
nativeIsRegisteredForRemoteNotifications
.
reset
();
nativeCheckPermissions
.
reset
();
});
after
(()
=>
{
...
...
@@ -124,6 +128,7 @@ describe("NotificationsIOS", () => {
nativeCancelLocalNotification
=
null
;
nativeCancelAllLocalNotifications
=
null
;
nativeIsRegisteredForRemoteNotifications
=
null
;
nativeCheckPermissions
=
null
;
NotificationsIOS
=
null
;
NotificationAction
=
null
;
...
...
@@ -309,4 +314,12 @@ describe("NotificationsIOS", () => {
});
});
describe
(
"
Check permissions
"
,
()
=>
{
it
(
"
should call native check permissions
"
,
()
=>
{
NotificationsIOS
.
checkPermissions
();
expect
(
nativeCheckPermissions
).
to
.
have
.
been
.
calledWith
();
});
});
});
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