Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
react-native-fcm
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
ym
react-native-fcm
Commits
832258da
Commit
832258da
authored
Feb 12, 2018
by
Libin Lu
Committed by
GitHub
Feb 12, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #779 from ditkachuk/detele-token
Add deleteEntityToken and getEntityToken methods
parents
15dc4489
3cb6099a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
16 deletions
+79
-16
android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java
...rc/main/java/com/evollu/react/fcm/FIRMessagingModule.java
+25
-1
index.js
index.js
+8
-0
ios/RNFIRMessaging.m
ios/RNFIRMessaging.m
+46
-15
No files found.
android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java
View file @
832258da
...
@@ -86,6 +86,31 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -86,6 +86,31 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
}
}
}
}
@ReactMethod
public
void
getEntityFCMToken
(
Promise
promise
)
{
try
{
String
senderId
=
FirebaseApp
.
getInstance
().
getOptions
().
getGcmSenderId
();
String
token
=
FirebaseInstanceId
.
getInstance
().
getToken
(
senderId
,
"FCM"
);
Log
.
d
(
TAG
,
"Firebase token: "
+
token
);
promise
.
resolve
(
token
);
}
catch
(
Throwable
e
)
{
e
.
printStackTrace
();
promise
.
reject
(
null
,
e
.
getMessage
());
}
}
@ReactMethod
public
void
deleteEntityFCMToken
(
Promise
promise
)
{
try
{
String
senderId
=
FirebaseApp
.
getInstance
().
getOptions
().
getGcmSenderId
();
FirebaseInstanceId
.
getInstance
().
deleteToken
(
senderId
,
"FCM"
);
promise
.
resolve
(
null
);
}
catch
(
Throwable
e
)
{
e
.
printStackTrace
();
promise
.
reject
(
null
,
e
.
getMessage
());
}
}
@ReactMethod
@ReactMethod
public
void
deleteInstanceId
(
Promise
promise
){
public
void
deleteInstanceId
(
Promise
promise
){
try
{
try
{
...
@@ -307,4 +332,3 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
...
@@ -307,4 +332,3 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
sendEvent
(
"FCMNotificationReceived"
,
parseIntent
(
intent
));
sendEvent
(
"FCMNotificationReceived"
,
parseIntent
(
intent
));
}
}
}
}
index.js
View file @
832258da
...
@@ -68,6 +68,14 @@ FCM.getFCMToken = () => {
...
@@ -68,6 +68,14 @@ FCM.getFCMToken = () => {
return
RNFIRMessaging
.
getFCMToken
();
return
RNFIRMessaging
.
getFCMToken
();
};
};
FCM
.
getEntityFCMToken
=
()
=>
{
return
RNFIRMessaging
.
getEntityFCMToken
();
}
FCM
.
deleteEntityFCMToken
=
()
=>
{
return
RNFIRMessaging
.
deleteEntityFCMToken
();
}
FCM
.
deleteInstanceId
=
()
=>
{
FCM
.
deleteInstanceId
=
()
=>
{
return
RNFIRMessaging
.
deleteInstanceId
();
return
RNFIRMessaging
.
deleteInstanceId
();
};
};
...
...
ios/RNFIRMessaging.m
View file @
832258da
...
@@ -140,7 +140,7 @@ typedef NS_ENUM(NSUInteger, UNNotificationActionType) {
...
@@ -140,7 +140,7 @@ typedef NS_ENUM(NSUInteger, UNNotificationActionType) {
+
(
UNNotificationAction
*
)
UNNotificationAction
:(
id
)
json
{
+
(
UNNotificationAction
*
)
UNNotificationAction
:(
id
)
json
{
NSDictionary
<
NSString
*
,
id
>
*
details
=
[
self
NSDictionary
:
json
];
NSDictionary
<
NSString
*
,
id
>
*
details
=
[
self
NSDictionary
:
json
];
NSString
*
identifier
=
[
RCTConvert
NSString
:
details
[
@"id"
]];
NSString
*
identifier
=
[
RCTConvert
NSString
:
details
[
@"id"
]];
NSString
*
title
=
[
RCTConvert
NSString
:
details
[
@"title"
]];
NSString
*
title
=
[
RCTConvert
NSString
:
details
[
@"title"
]];
UNNotificationActionOptions
options
=
[
RCTConvert
UNNotificationActionOptions
:
details
[
@"options"
]];
UNNotificationActionOptions
options
=
[
RCTConvert
UNNotificationActionOptions
:
details
[
@"options"
]];
...
@@ -152,11 +152,11 @@ typedef NS_ENUM(NSUInteger, UNNotificationActionType) {
...
@@ -152,11 +152,11 @@ typedef NS_ENUM(NSUInteger, UNNotificationActionType) {
return
[
UNTextInputNotificationAction
actionWithIdentifier
:
identifier
title
:
title
options
:
options
textInputButtonTitle
:
textInputButtonTitle
textInputPlaceholder
:
textInputPlaceholder
];
return
[
UNTextInputNotificationAction
actionWithIdentifier
:
identifier
title
:
title
options
:
options
textInputButtonTitle
:
textInputButtonTitle
textInputPlaceholder
:
textInputPlaceholder
];
}
}
return
[
UNNotificationAction
actionWithIdentifier
:
identifier
return
[
UNNotificationAction
actionWithIdentifier
:
identifier
title:
title
title:
title
options:
options
];
options:
options
];
}
}
RCT_ENUM_CONVERTER
(
UNNotificationActionType
,
(@{
RCT_ENUM_CONVERTER
(
UNNotificationActionType
,
(@{
...
@@ -180,9 +180,9 @@ RCT_MULTI_ENUM_CONVERTER(UNNotificationActionOptions, (@{
...
@@ -180,9 +180,9 @@ RCT_MULTI_ENUM_CONVERTER(UNNotificationActionOptions, (@{
+
(
UNNotificationCategory
*
)
UNNotificationCategory
:(
id
)
json
{
+
(
UNNotificationCategory
*
)
UNNotificationCategory
:(
id
)
json
{
NSDictionary
<
NSString
*
,
id
>
*
details
=
[
self
NSDictionary
:
json
];
NSDictionary
<
NSString
*
,
id
>
*
details
=
[
self
NSDictionary
:
json
];
NSString
*
identifier
=
[
RCTConvert
NSString
:
details
[
@"id"
]];
NSString
*
identifier
=
[
RCTConvert
NSString
:
details
[
@"id"
]];
NSMutableArray
*
actions
=
[[
NSMutableArray
alloc
]
init
];
NSMutableArray
*
actions
=
[[
NSMutableArray
alloc
]
init
];
for
(
NSDictionary
*
actionDict
in
details
[
@"actions"
])
{
for
(
NSDictionary
*
actionDict
in
details
[
@"actions"
])
{
[
actions
addObject
:[
RCTConvert
UNNotificationAction
:
actionDict
]];
[
actions
addObject
:[
RCTConvert
UNNotificationAction
:
actionDict
]];
...
@@ -261,7 +261,7 @@ RCT_EXPORT_MODULE();
...
@@ -261,7 +261,7 @@ RCT_EXPORT_MODULE();
if
([
response
isKindOfClass
:
UNTextInputNotificationResponse
.
class
])
{
if
([
response
isKindOfClass
:
UNTextInputNotificationResponse
.
class
])
{
[
data
setValue
:[(
UNTextInputNotificationResponse
*
)
response
userText
]
forKey
:
@"_userText"
];
[
data
setValue
:[(
UNTextInputNotificationResponse
*
)
response
userText
]
forKey
:
@"_userText"
];
}
}
NSDictionary
*
userInfo
=
@{
@"data"
:
data
,
@"completionHandler"
:
completionHandler
};
NSDictionary
*
userInfo
=
@{
@"data"
:
data
,
@"completionHandler"
:
completionHandler
};
static
dispatch_once_t
onceToken
;
static
dispatch_once_t
onceToken
;
...
@@ -314,7 +314,7 @@ RCT_EXPORT_MODULE();
...
@@ -314,7 +314,7 @@ RCT_EXPORT_MODULE();
-
(
void
)
addListener
:(
NSString
*
)
eventName
{
-
(
void
)
addListener
:(
NSString
*
)
eventName
{
[
super
addListener
:
eventName
];
[
super
addListener
:
eventName
];
if
([
eventName
isEqualToString
:
FCMNotificationReceived
]
&&
initialNotificationActionResponse
)
{
if
([
eventName
isEqualToString
:
FCMNotificationReceived
]
&&
initialNotificationActionResponse
)
{
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
FCMNotificationReceived
object
:
self
userInfo
:
[
initialNotificationActionResponse
copy
]];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
FCMNotificationReceived
object
:
self
userInfo
:
[
initialNotificationActionResponse
copy
]];
}
}
...
@@ -358,16 +358,47 @@ RCT_EXPORT_METHOD(getFCMToken:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromi
...
@@ -358,16 +358,47 @@ RCT_EXPORT_METHOD(getFCMToken:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromi
resolve
([
FIRMessaging
messaging
].
FCMToken
);
resolve
([
FIRMessaging
messaging
].
FCMToken
);
}
}
RCT_EXPORT_METHOD
(
getEntityFCMToken
:
(
RCTPromiseResolveBlock
)
resolve
rejecter
:
(
RCTPromiseRejectBlock
)
reject
)
{
FIROptions
*
options
=
FIROptions
.
defaultOptions
;
NSString
*
entity
=
options
.
GCMSenderID
;
NSData
*
deviceToken
=
[
FIRMessaging
messaging
].
APNSToken
;
[[
FIRInstanceID
instanceID
]
tokenWithAuthorizedEntity
:
entity
scope
:
kFIRInstanceIDScopeFirebaseMessaging
options
:
@{
@"apns_token"
:
deviceToken
}
handler
:^
(
NSString
*
_Nullable
token
,
NSError
*
_Nullable
error
)
{
if
(
error
!=
nil
)
{
reject
([
NSString
stringWithFormat
:
@"%ld"
,
error
.
code
],
error
.
localizedDescription
,
nil
);
}
else
{
resolve
(
token
);
}
}];
}
RCT_EXPORT_METHOD
(
deleteEntityFCMToken
:
(
RCTPromiseResolveBlock
)
resolve
rejecter
:
(
RCTPromiseRejectBlock
)
reject
)
{
FIROptions
*
options
=
FIROptions
.
defaultOptions
;;
NSString
*
entity
=
options
.
GCMSenderID
;
[[
FIRInstanceID
instanceID
]
deleteTokenWithAuthorizedEntity
:
entity
scope
:
kFIRInstanceIDScopeFirebaseMessaging
handler
:^
(
NSError
*
_Nullable
error
)
{
if
(
error
!=
nil
)
{
reject
([
NSString
stringWithFormat
:
@"%ld"
,
error
.
code
],
error
.
localizedDescription
,
nil
);
}
else
{
resolve
(
nil
);
}
}];
}
RCT_EXPORT_METHOD
(
deleteInstanceId
:
(
RCTPromiseResolveBlock
)
resolve
rejecter
:
(
RCTPromiseRejectBlock
)
reject
)
RCT_EXPORT_METHOD
(
deleteInstanceId
:
(
RCTPromiseResolveBlock
)
resolve
rejecter
:
(
RCTPromiseRejectBlock
)
reject
)
{
{
[[
FIRInstanceID
instanceID
]
deleteIDWithHandler
:
^
(
NSError
*
_Nullable
error
)
{
[[
FIRInstanceID
instanceID
]
deleteIDWithHandler
:
^
(
NSError
*
_Nullable
error
)
{
if
(
error
!=
nil
)
{
if
(
error
!=
nil
)
{
reject
([
NSString
stringWithFormat
:
@"%ld"
,
error
.
code
],
error
.
localizedDescription
,
nil
);
reject
([
NSString
stringWithFormat
:
@"%ld"
,
error
.
code
],
error
.
localizedDescription
,
nil
);
}
else
{
}
else
{
resolve
(
nil
);
resolve
(
nil
);
}
}
}];
}];
}
}
-
(
void
)
messaging
:(
nonnull
FIRMessaging
*
)
messaging
didRefreshRegistrationToken
:(
nonnull
NSString
*
)
fcmToken
{
-
(
void
)
messaging
:(
nonnull
FIRMessaging
*
)
messaging
didRefreshRegistrationToken
:(
nonnull
NSString
*
)
fcmToken
{
...
...
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