Comments (10)
We are working by Topics, so that's why I don't implement token share. You can make something like this
PWAShell.webView.evaluateJavaScript("this.dispatchEvent(new CustomEvent('FCM-token-handle', { detail: token }))")
and catch this on web side.
from ios-pwa-wrap.
We are working by Topics, so that's why I don't implement token share. You can make something like this
PWAShell.webView.evaluateJavaScript("this.dispatchEvent(new CustomEvent('FCM-token-handle', { detail: token }))")
and catch this on web side.Could you please provide a tutorial on how to do this? I need only the device id.
I did it in this way. May be it will helps you.
PushNotifications.swift
func returnPermissionResult(isGranted: Bool){
DispatchQueue.main.async(execute: {
if (isGranted){
Messaging.messaging().token { token, error in
if let error = error {
print("Error fetching FCM registration token: \(error)")
} else if let token = token {
print("FCM registration token: \(token)")
eDrive.webView.evaluateJavaScript("this.dispatchEvent(new CustomEvent('push-permission-request', { detail: { state: 'granted', token: '\(token)' }}))")
}
}
}
else {
eDrive.webView.evaluateJavaScript("this.dispatchEvent(new CustomEvent('push-permission-request', { detail: { state: 'denied' }}))")
}
})
}
from ios-pwa-wrap.
Hi,
I'm needing the id of the token to save in the database.
In which file do I need to add this code?
PWAShell.webView.evaluateJavaScript("this.dispatchEvent(new CustomEvent('FCM-token-handle', { detail: token }))")
And how would you get it in javascript?
Thanks.
Great job.
from ios-pwa-wrap.
Hi, I'm needing the id of the token to save in the database. In which file do I need to add this code?
PWAShell.webView.evaluateJavaScript("this.dispatchEvent(new CustomEvent('FCM-token-handle', { detail: token }))")
And how would you get it in javascript?
Thanks. Great job.
I managed it by listening for the event getting triggered in the js code and can pick up on the fcm token from there
from ios-pwa-wrap.
@gareth-johnstone could you please put a code example on the frontend to get the token?
from ios-pwa-wrap.
@gareth-johnstone could you please put a code example on the frontend to get the token?
window.addEventListener('FCM-token-handle', function (message) { console.info(message) // intentionally left in /* FCM token is returned as "Optional(\"<TOKEN>\")" So just tidying it up with some regex so its useable. */ var fcmToken = message.detail.match(/\"(.*?)\"/)[0].replace(/\"/g, '')
Not the full snippet, copy paste from my phone 😂 but you get the idea
from ios-pwa-wrap.
I need help please, I'm not getting it.
In the frontend I was able to trace the event, but it has the error when loading the token.
I made the firebase settings, and changed some swift files.
https://firebase.google.com/docs/cloud-messaging/ios/client?authuser=0&hl=pt#swift_4
Frontend:
if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers['FCM-token-handle']) {
window.iosFcmTokenHandle = true;
}
pushPermissionRequest = function(){
if (window.iOSPushCapability) window.webkit.messageHandlers['push-permission-request'].postMessage('push-permission-request');
if (window.iosFcmTokenHandle) window.webkit.messageHandlers['FCM-token-handle'].postMessage('FCM-token-handle');
}
pushPermissionRequest();
// Get the FCM token
window.addEventListener('FCM-token-handle', (token) => {
alert('FCM-token-handle...');
alert(token.detail);
});
In the project folder, I changed the following files:
WebView.swift
userContentController.add(WKSMH, name: "FCM-token-handle")
ViewController.swift
if message.name =="FCM-token-handle" {
handleFCMToken()
}
PushNotifications.swift
func handleFCMToken(){
DispatchQueue.main.async(execute: {
Messaging.messaging().token { token, error on
if let error = error {
print("Error fetching FCM registration token: \(error)")
PWAapp.webView.evaluateJavaScript("this.dispatchEvent(new CustomEvent('FCM-token-handle', { detail: 'ERROR GET TOKEN' }))")
} else if let token = token {
print("FCM registration token: \(token)")
PWAapp.webView.evaluateJavaScript("this.dispatchEvent(new CustomEvent('FCM-token-handle', { detail: token }))")
}
}
})
}
After running the event, it always falls on ERROR GET TOKEN, what am I doing wrong?
from ios-pwa-wrap.
We are working by Topics, so that's why I don't implement token share. You can make something like this
PWAShell.webView.evaluateJavaScript("this.dispatchEvent(new CustomEvent('FCM-token-handle', { detail: token }))")
and catch this on web side.
Could you please provide a tutorial on how to do this?
I need only the device id.
from ios-pwa-wrap.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ios-pwa-wrap.