*)supportedEvents {
return @[
- MESSAGING_SUBSYSTEM_EVENT,
- MESSAGING_SUBSYSTEM_ERROR,
- MESSAGING_TOKEN_REFRESH,
- MESSAGING_MESSAGE_RECEIVED_LOCAL,
- MESSAGING_MESSAGE_RECEIVED_REMOTE];
+ MESSAGING_SUBSYSTEM_EVENT,
+ MESSAGING_SUBSYSTEM_ERROR,
+ MESSAGING_TOKEN_REFRESH,
+ MESSAGING_MESSAGE_RECEIVED_LOCAL,
+ MESSAGING_MESSAGE_RECEIVED_REMOTE];
}
- (void) sendJSEvent:(NSString *)title
@@ -318,9 +392,9 @@ - (void) sendJSEvent:(NSString *)title
@try {
[self sendEventWithName:title
body:@{
- @"eventName": title,
- @"body": props
- }];
+ @"eventName": title,
+ @"body": props
+ }];
}
@catch (NSException *err) {
NSLog(@"An error occurred in sendJSEvent: %@", [err debugDescription]);
diff --git a/ios/Firestack/FirestackStorage.m b/ios/Firestack/FirestackStorage.m
index d88a19a..2da5377 100644
--- a/ios/Firestack/FirestackStorage.m
+++ b/ios/Firestack/FirestackStorage.m
@@ -25,7 +25,12 @@ - (dispatch_queue_t)methodQueue
path:(NSString *) path
callback:(RCTResponseSenderBlock) callback)
{
- FIRStorageReference *storageRef = [[FIRStorage storage] referenceForURL:storageUrl];
+ FIRStorageReference *storageRef;
+ if (storageUrl == nil ) {
+ storageRef = [[FIRStorage storage] reference];
+ } else {
+ storageRef = [[FIRStorage storage] referenceForURL:storageUrl];
+ }
FIRStorageReference *fileRef = [storageRef child:path];
[fileRef downloadURLWithCompletion:^(NSURL * _Nullable URL, NSError * _Nullable error) {
if (error != nil) {
@@ -52,14 +57,13 @@ - (dispatch_queue_t)methodQueue
metadata:(NSDictionary *)metadata
callback:(RCTResponseSenderBlock) callback)
{
+ FIRStorageReference *storageRef;
if (urlStr == nil) {
- NSError *err = [[NSError alloc] init];
- [err setValue:@"Storage configuration error" forKey:@"name"];
- [err setValue:@"Call setStorageUrl() first" forKey:@"description"];
- return callback(@[err]);
+ storageRef = [[FIRStorage storage] reference];
+ } else {
+ storageRef = [[FIRStorage storage] referenceForURL:urlStr];
}
- FIRStorageReference *storageRef = [[FIRStorage storage] referenceForURL:urlStr];
FIRStorageReference *uploadRef = [storageRef child:name];
FIRStorageMetadata *firmetadata = [[FIRStorageMetadata alloc] initWithDictionary:metadata];
@@ -157,6 +161,7 @@ - (void) addUploadObservers:(FIRStorageUploadTask *) uploadTask
case FIRStorageErrorCodeUnknown:
// Unknown error occurred, inspect the server response
[errProps setValue:@"Unknown error" forKey:@"description"];
+ NSLog(@"Unknown error: %@", snapshot.error);
break;
}
diff --git a/lib/modules/cloudmessaging.js b/lib/modules/cloudmessaging.js
new file mode 100644
index 0000000..73b390b
--- /dev/null
+++ b/lib/modules/cloudmessaging.js
@@ -0,0 +1,108 @@
+import {Platform, NativeModules, NativeEventEmitter} from 'react-native';
+const FirestackCloudMessaging = NativeModules.FirestackCloudMessaging;
+const FirestackCloudMessagingEvt = new NativeEventEmitter(FirestackCloudMessaging);
+
+import promisify from '../utils/promisify'
+import { Base, ReferenceBase } from './base'
+
+const defaultPermissions = {
+ 'badge': 1,
+ 'sound': 2,
+ 'alert': 3
+}
+export class CloudMessaging extends Base {
+ constructor(firestack, options = {}) {
+ super(firestack, options);
+
+ this.requestedPermissions = Object.assign({}, defaultPermissions, options.permissions);
+ }
+ get namespace() {
+ return 'firestack:cloudMessaging'
+ }
+ getToken() {
+ this.log.info('getToken for cloudMessaging');
+ return promisify('getToken', FirestackCloudMessaging)();
+ }
+
+ // Request FCM permissions
+ requestPermissions(requestedPermissions = {}) {
+ if (Platform.OS === 'ios') {
+ const mergedRequestedPermissions = Object.assign({},
+ this.requestedPermissions,
+ requestedPermissions);
+ return promisify('requestPermissions', FirestackCloudMessaging)(mergedRequestedPermissions)
+ .then(perms => {
+
+ return perms;
+ });
+ }
+ }
+
+ sendMessage(details:Object = {}, type:string='local') {
+ const methodName = `send${type == 'local' ? 'Local' : 'Remote'}`
+ this.log.info('sendMessage', methodName, details);
+ return promisify(methodName, FirestackCloudMessaging)(details);
+ }
+ scheduleMessage(details:Object = {}, type:string='local') {
+ const methodName = `schedule${type == 'local' ? 'Local' : 'Remote'}`
+ return promisify(methodName, FirestackCloudMessaging)(details);
+ }
+ // OLD
+ send(senderId, messageId, messageType, msg){
+ return promisify('send', FirestackCloudMessaging)(senderId, messageId, messageType, msg);
+ }
+ //
+ listenForTokenRefresh(callback) {
+ this.log.info('Setting up listenForTokenRefresh callback');
+ const sub = this._on('FirestackRefreshToken', callback, FirestackCloudMessagingEvt);
+ return promisify(() => sub, FirestackCloudMessaging)(sub);
+ }
+ unlistenForTokenRefresh() {
+ this.log.info('Unlistening for TokenRefresh');
+ this._off('FirestackRefreshToken');
+ }
+ subscribeToTopic(topic) {
+ this.log.info('subscribeToTopic ' + topic);
+ const finalTopic = `/topics/${topic}`
+ return promisify('subscribeToTopic', FirestackCloudMessaging)(finalTopic);
+ }
+ unsubscribeFromTopic(topic) {
+ this.log.info('unsubscribeFromTopic ' + topic);
+ const finalTopic = `/topics/${topic}`
+ return promisify('unsubscribeFromTopic', FirestackCloudMessaging)(finalTopic);
+ }
+ // New api
+ onRemoteMessage(callback) {
+ this.log.info('On remote message callback');
+ const sub = this._on('messaging_remote_event_received', callback, FirestackCloudMessagingEvt);
+ return promisify(() => sub, FirestackCloudMessaging)(sub);
+ }
+
+ onLocalMessage(callback) {
+ this.log.info('on local callback');
+ const sub = this._on('messaging_local_event_received', callback, FirestackCloudMessagingEvt);
+ return promisify(() => sub, FirestackCloudMessaging)(sub);
+ }
+
+ // Original API
+ listenForReceiveNotification(callback) {
+ this.log.info('Setting up listenForReceiveNotification callback');
+ const sub = this._on('FirestackReceiveNotification', callback, FirestackCloudMessagingEvt);
+ return promisify(() => sub, FirestackCloudMessaging)(sub);
+ }
+ unlistenForReceiveNotification() {
+ this.log.info('Unlistening for ReceiveNotification');
+ this._off('FirestackRefreshToken');
+ }
+ listenForReceiveUpstreamSend(callback) {
+ this.log.info('Setting up send callback');
+ const sub = this._on('FirestackUpstreamSend', callback, FirestackCloudMessagingEvt);
+ return promisify(() => sub, FirestackCloudMessaging)(sub);
+ }
+ unlistenForReceiveUpstreamSend() {
+ this.log.info('Unlistening for send');
+ this._off('FirestackUpstreamSend');
+ }
+}
+
+export default CloudMessaging
\ No newline at end of file
diff --git a/lib/modules/messaging.js b/lib/modules/messaging.js
index 877cf29..696e5e4 100644
--- a/lib/modules/messaging.js
+++ b/lib/modules/messaging.js
@@ -5,14 +5,42 @@ import promisify from '../utils/promisify';
const FirestackCloudMessaging = NativeModules.FirestackCloudMessaging;
const FirestackCloudMessagingEvt = new NativeEventEmitter(FirestackCloudMessaging);
+const defaultPermissions = {
+ 'badge': 1,
+ 'sound': 2,
+ 'alert': 3
+}
+
/**
* @class Messaging
*/
export default class Messaging extends Base {
constructor(firestack, options = {}) {
super(firestack, options);
- }
-
+ //this.requestedPermissions = Object.assign({}, defaultPermissions, options.permissions);
+
+ }
+
+ // Request FCM permissions
+ // requestPermissions(requestedPermissions = {}) {
+ // // if (Platform.OS === 'ios') {
+ // const mergedRequestedPermissions = Object.assign({},
+ // this.requestedPermissions,
+ // requestedPermissions);
+ // return promisify('requestPermissions', FirestackCloudMessaging)(mergedRequestedPermissions)
+ // .then(perms => {
+
+ // return perms;
+ // });
+ // // }
+ // }
+
+ // Request FCM permissions
+ requestPermissions() {
+ this.log.info('requesting permissions');
+ return promisify('requestPermissions', FirestackCloudMessaging)();
+ // }
+ }
/*
* WEB API
*/
@@ -48,8 +76,14 @@ export default class Messaging extends Base {
return promisify('getToken', FirestackCloudMessaging)();
}
+ getInitialNotification(){
+ this.log.info('user launched app from notification');
+ return promisify('getInitialNotification',FirestackCloudMessaging)();
+ }
+
sendMessage(details: Object = {}, type: string = 'local') {
const methodName = `send${type == 'local' ? 'Local' : 'Remote'}`;
+ this.log.info(methodName);
this.log.info('sendMessage', methodName, details);
return promisify(methodName, FirestackCloudMessaging)(details);
}
@@ -60,8 +94,8 @@ export default class Messaging extends Base {
}
// OLD
- send(senderId, messageId, messageType, msg) {
- return promisify('send', FirestackCloudMessaging)(senderId, messageId, messageType, msg);
+ send(messageId, msg,ttl) {
+ return promisify('send', FirestackCloudMessaging)(messageId, msg,ttl);
}
//
@@ -111,7 +145,7 @@ export default class Messaging extends Base {
console.warn('Firestack: listenForReceiveNotification is now deprecated, please use onMessage');
return this.onMessage(...args);
}
-
+
/**
* @deprecated
* @param args
diff --git a/lib/utils/window-or-global.js b/lib/utils/window-or-global.js
index 3228c06..7b64020 100644
--- a/lib/utils/window-or-global.js
+++ b/lib/utils/window-or-global.js
@@ -2,4 +2,4 @@
// https://github.com/purposeindustries/window-or-global
module.exports = (typeof self === 'object' && self.self === self && self) ||
(typeof global === 'object' && global.global === global && global) ||
- this
\ No newline at end of file
+ {}
\ No newline at end of file
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy