@smartface/plugin-firebase
Version:
Smartface Firebase Plugin for Smartface Native Framework
118 lines • 5.01 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var invocation_1 = __importDefault(require("@smartface/native/util/iOS/invocation"));
var Messaging = /** @class */ (function () {
function Messaging() {
}
/**
* Asynchronously subscribes to a topic.
*
* @method subscribeToTopic
* @param {String} topic
* @android
* @ios
* @since 0.1
*/
Messaging.subscribeToTopic = function (topic) {
Messaging.ios.native.subscribeToTopic(topic);
};
/**
* Asynchronously unsubscribe from a topic.
*
* @method unsubscribeFromTopic
* @param {String} topic
* @android
* @ios
* @since 0.1
*/
Messaging.unsubscribeFromTopic = function (topic) {
Messaging.ios.native.unsubscribeFromTopic(topic);
};
/**
* iOS : Returns the FCM token.
* Android : Returns the notification token.
*
* @method getToken
* @android
* @ios
* @since 0.1
*/
Messaging.getToken = function (callback) {
typeof callback === 'function' && callback(Messaging.ios.native.FCMToken());
};
Messaging.ios = {
native: {
messaging: function () { return invocation_1.default.invokeClassMethod('FIRMessaging', 'messaging', [], 'NSObject'); },
FCMToken: function () { return invocation_1.default.invokeInstanceMethod(Messaging.ios.native.messaging(), 'FCMToken', [], 'NSString'); },
subscribeToTopic: function (topic) {
// @ts-ignore
var argTopic = new invocation_1.default.Argument({
type: 'NSString',
value: topic
});
// @ts-ignore
invocation_1.default.invokeInstanceMethod(Messaging.ios.native.messaging(), 'subscribeToTopic:', [argTopic]);
},
unsubscribeFromTopic: function (topic) {
// @ts-ignore
var argTopic = new invocation_1.default.Argument({
type: 'NSString',
value: topic
});
// @ts-ignore
invocation_1.default.invokeInstanceMethod(Messaging.ios.native.messaging(), 'unsubscribeFromTopic:', [argTopic]);
},
messagingDidReceiveRegistrationToken: function () {
if (!Messaging.ios.native.messagingDelegate) {
var messagingAlloc = invocation_1.default.invokeClassMethod('MessagingDelegate', 'alloc', [], 'id');
Messaging.ios.native.messagingDelegate = invocation_1.default.invokeInstanceMethod(messagingAlloc, 'init', [], 'NSObject');
// @ts-ignore
var argDelegate = new invocation_1.default.Argument({
type: 'NSObject',
value: Messaging.ios.native.messagingDelegate
});
// @ts-ignore
invocation_1.default.invokeInstanceMethod(Messaging.ios.native.messaging(), 'setDelegate:', [argDelegate]);
}
// @ts-ignore
var argMessaggingDidRecieve = new invocation_1.default.Argument({
type: 'JSValue',
value: function (e) {
if (typeof Messaging.ios.onTokenReflesh === 'function') {
Messaging.ios.onTokenReflesh(e.fcmToken);
}
}
});
// @ts-ignore
invocation_1.default.invokeInstanceMethod(Messaging.ios.native.messagingDelegate, 'setMessagingDidReceiveRegistrationToken:', [
argMessaggingDidRecieve
]);
}
},
/**
* The FCM token is used to identify this device so that FCM can send notifications to it.
* It is associated with your APNS token when the APNS token is supplied, so that sending
* messages to the FCM token will be delivered over APNS.
*
* The FCM token is sometimes refreshed automatically. `onTokenReflesh` method will be called once a token is
* available, or has been refreshed. Typically it should be called once per app start, but
* may be called more often, if token is invalidated or updated.
*
* Once you have an FCM token, you should send it to your application server, so it can use
* the FCM token to send notifications to your device.
*
* @method onTokenReflesh
* @ios
* @since 0.1
*/
onTokenReflesh: function () { }
};
return Messaging;
}());
Messaging.ios.native.messagingDidReceiveRegistrationToken();
exports.default = Messaging;
module.exports = Messaging;
//# sourceMappingURL=messaging-iOS.js.map