added firebase

This commit is contained in:
Xeovalyte 2022-09-29 16:34:00 +02:00
parent 63e5b67d2e
commit 53fb637c27
4 changed files with 99 additions and 1 deletions

View File

@ -19,6 +19,7 @@
<script setup> <script setup>
import { doc, getFirestore, serverTimestamp, writeBatch, collection, getDoc } from "firebase/firestore"; import { doc, getFirestore, serverTimestamp, writeBatch, collection, getDoc } from "firebase/firestore";
import { getAuth, onAuthStateChanged, signInWithEmailAndPassword } from "firebase/auth"; import { getAuth, onAuthStateChanged, signInWithEmailAndPassword } from "firebase/auth";
import { PushNotifications } from '@capacitor/push-notifications';
const db = getFirestore() const db = getFirestore()
const route = useRoute() const route = useRoute()
@ -54,6 +55,8 @@ onMounted(() => {
isAuthenticated.value = true isAuthenticated.value = true
setupNotifications()
} else { } else {
isAuthenticated.value = false isAuthenticated.value = false
user.value = null user.value = null
@ -78,6 +81,50 @@ const getPersons = async (persons) => {
} }
} }
const setupNotifications = () => {
console.log('Initializing HomePage');
// Request permission to use push notifications
// iOS will prompt user and return if they granted permission or not
// Android will just grant without prompting
PushNotifications.requestPermissions().then(result => {
if (result.receive === 'granted') {
// Register with Apple / Google to receive push via APNS/FCM
PushNotifications.register();
} else {
// Show some error
}
});
// On success, we should be able to receive notifications
PushNotifications.addListener('registration',
(token) => {
alert('Push registration success, token: ' + token.value);
}
);
// Some issue with our setup and push will not work
PushNotifications.addListener('registrationError',
(error) => {
alert('Error on registration: ' + JSON.stringify(error));
}
);
// Show us the notification payload if the app is open on our device
PushNotifications.addListener('pushNotificationReceived',
(notification) => {
alert('Push received: ' + JSON.stringify(notification));
}
);
// Method called when tapping on a notification
PushNotifications.addListener('pushNotificationActionPerformed',
(notification) => {
alert('Push action performed: ' + JSON.stringify(notification));
}
);
}
const ledenlijst = ref([]) const ledenlijst = ref([])
provide('firebase', { db, ledenlijst, isAuthenticated, user, userData, userPersons, auth, userAllPersons, getPersons, calEvents, news }) provide('firebase', { db, ledenlijst, isAuthenticated, user, userData, userPersons, auth, userAllPersons, getPersons, calEvents, news })

View File

@ -1,5 +1,6 @@
import UIKit import UIKit
import Capacitor import Capacitor
import Firebase
@UIApplicationMain @UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate { class AppDelegate: UIResponder, UIApplicationDelegate {
@ -8,6 +9,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch. // Override point for customization after application launch.
FirebaseApp.configure()
return true return true
} }
@ -46,4 +48,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return ApplicationDelegateProxy.shared.application(application, continue: userActivity, restorationHandler: restorationHandler) return ApplicationDelegateProxy.shared.application(application, continue: userActivity, restorationHandler: restorationHandler)
} }
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
Messaging.messaging().token(completion: { (token, error) in
if let error = error {
NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
} else if let token = token {
NotificationCenter.default.post(name: .capacitorDidRegisterForRemoteNotifications, object: token)
}
})
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
}
} }

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CLIENT_ID</key>
<string>160377508482-r1822jlgp287ks09ajb27qg1oko80lpr.apps.googleusercontent.com</string>
<key>REVERSED_CLIENT_ID</key>
<string>com.googleusercontent.apps.160377508482-r1822jlgp287ks09ajb27qg1oko80lpr</string>
<key>API_KEY</key>
<string>AIzaSyAjlJhSGUMzTFVx-ICML_8DVlDFUQqN8WY</string>
<key>GCM_SENDER_ID</key>
<string>160377508482</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>com.reddingsbrigadewaddinxveen.wrbapp</string>
<key>PROJECT_ID</key>
<string>wrbapp</string>
<key>STORAGE_BUCKET</key>
<string>wrbapp.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<false></false>
<key>IS_ANALYTICS_ENABLED</key>
<false></false>
<key>IS_APPINVITE_ENABLED</key>
<true></true>
<key>IS_GCM_ENABLED</key>
<true></true>
<key>IS_SIGNIN_ENABLED</key>
<true></true>
<key>GOOGLE_APP_ID</key>
<string>1:160377508482:ios:0079517b62e9684f879a9b</string>
</dict>
</plist>

View File

@ -16,7 +16,7 @@ end
target 'App' do target 'App' do
capacitor_pods capacitor_pods
# Add your Pods here pod 'Firebase/Messaging'
end end
post_install do |installer| post_install do |installer|