fix(ios): use correct Capacitor API for plugin method registration
Fixed plugin registration to use proper Capacitor native bridge API: API Fix: - Changed from window.Capacitor.nativePromise to cap.nativePromise - Added proper initialization wait for Capacitor to be available - Wrapped in IIFE for proper scoping Method Registration: - All methods now use cap.nativePromise(pluginName, methodName, options) - Methods properly bridge to native Swift implementation - Added initialization check to wait for Capacitor if not ready Fixes: - Error: 'requestNotificationPermissions is not a function' - Plugin methods now correctly call native bridge - Proper async initialization ensures Capacitor is ready Result: Permission buttons and all plugin methods should now work correctly
This commit is contained in:
@@ -1,75 +1,99 @@
|
|||||||
// Capacitor Plugins Registration
|
// Capacitor Plugins Registration
|
||||||
// This file registers the DailyNotification plugin for iOS
|
// This file registers the DailyNotification plugin for iOS
|
||||||
|
// Methods bridge to native Swift implementation via Capacitor's native bridge
|
||||||
|
|
||||||
window.Capacitor = window.Capacitor || {};
|
(function() {
|
||||||
window.Capacitor.Plugins = window.Capacitor.Plugins || {};
|
'use strict';
|
||||||
|
|
||||||
// Register DailyNotification plugin with method stubs
|
// Wait for Capacitor to be available
|
||||||
// Methods will be bridged to native Swift implementation
|
function registerPlugin() {
|
||||||
window.Capacitor.Plugins.DailyNotification = window.Capacitor.Plugins.DailyNotification || {
|
if (!window.Capacitor) {
|
||||||
// Permission methods
|
setTimeout(registerPlugin, 100);
|
||||||
checkPermissionStatus: function() {
|
return;
|
||||||
return window.Capacitor.nativePromise('DailyNotification', 'checkPermissionStatus', {});
|
}
|
||||||
},
|
|
||||||
requestNotificationPermissions: function() {
|
const cap = window.Capacitor;
|
||||||
return window.Capacitor.nativePromise('DailyNotification', 'requestNotificationPermissions', {});
|
if (!cap.Plugins) {
|
||||||
},
|
cap.Plugins = {};
|
||||||
checkPermissions: function() {
|
}
|
||||||
return window.Capacitor.nativePromise('DailyNotification', 'checkPermissions', {});
|
|
||||||
},
|
// Create plugin object with methods that call native bridge
|
||||||
requestPermissions: function() {
|
const DailyNotification = {
|
||||||
return window.Capacitor.nativePromise('DailyNotification', 'requestPermissions', {});
|
// Permission methods
|
||||||
},
|
checkPermissionStatus: function() {
|
||||||
// Notification methods
|
return cap.nativePromise('DailyNotification', 'checkPermissionStatus', {});
|
||||||
scheduleDailyNotification: function(options) {
|
},
|
||||||
return window.Capacitor.nativePromise('DailyNotification', 'scheduleDailyNotification', options || {});
|
requestNotificationPermissions: function() {
|
||||||
},
|
return cap.nativePromise('DailyNotification', 'requestNotificationPermissions', {});
|
||||||
getNotificationStatus: function() {
|
},
|
||||||
return window.Capacitor.nativePromise('DailyNotification', 'getNotificationStatus', {});
|
checkPermissions: function() {
|
||||||
},
|
return cap.nativePromise('DailyNotification', 'checkPermissions', {});
|
||||||
cancelAllNotifications: function() {
|
},
|
||||||
return window.Capacitor.nativePromise('DailyNotification', 'cancelAllNotifications', {});
|
requestPermissions: function() {
|
||||||
},
|
return cap.nativePromise('DailyNotification', 'requestPermissions', {});
|
||||||
// Status methods
|
},
|
||||||
checkStatus: function() {
|
// Notification methods
|
||||||
return window.Capacitor.nativePromise('DailyNotification', 'checkStatus', {});
|
scheduleDailyNotification: function(options) {
|
||||||
},
|
return cap.nativePromise('DailyNotification', 'scheduleDailyNotification', options || {});
|
||||||
// Channel methods
|
},
|
||||||
isChannelEnabled: function(options) {
|
getNotificationStatus: function() {
|
||||||
return window.Capacitor.nativePromise('DailyNotification', 'isChannelEnabled', options || {});
|
return cap.nativePromise('DailyNotification', 'getNotificationStatus', {});
|
||||||
},
|
},
|
||||||
openChannelSettings: function(options) {
|
cancelAllNotifications: function() {
|
||||||
return window.Capacitor.nativePromise('DailyNotification', 'openChannelSettings', options || {});
|
return cap.nativePromise('DailyNotification', 'cancelAllNotifications', {});
|
||||||
},
|
},
|
||||||
// Configuration methods
|
// Status methods
|
||||||
configure: function(options) {
|
checkStatus: function() {
|
||||||
return window.Capacitor.nativePromise('DailyNotification', 'configure', options || {});
|
return cap.nativePromise('DailyNotification', 'checkStatus', {});
|
||||||
},
|
},
|
||||||
configureNativeFetcher: function(options) {
|
// Channel methods
|
||||||
return window.Capacitor.nativePromise('DailyNotification', 'configureNativeFetcher', options || {});
|
isChannelEnabled: function(options) {
|
||||||
},
|
return cap.nativePromise('DailyNotification', 'isChannelEnabled', options || {});
|
||||||
// Battery/Power methods
|
},
|
||||||
getBatteryStatus: function() {
|
openChannelSettings: function(options) {
|
||||||
return window.Capacitor.nativePromise('DailyNotification', 'getBatteryStatus', {});
|
return cap.nativePromise('DailyNotification', 'openChannelSettings', options || {});
|
||||||
},
|
},
|
||||||
getPowerState: function() {
|
// Configuration methods
|
||||||
return window.Capacitor.nativePromise('DailyNotification', 'getPowerState', {});
|
configure: function(options) {
|
||||||
},
|
return cap.nativePromise('DailyNotification', 'configure', options || {});
|
||||||
requestBatteryOptimizationExemption: function() {
|
},
|
||||||
return window.Capacitor.nativePromise('DailyNotification', 'requestBatteryOptimizationExemption', {});
|
configureNativeFetcher: function(options) {
|
||||||
},
|
return cap.nativePromise('DailyNotification', 'configureNativeFetcher', options || {});
|
||||||
// Exact alarm methods
|
},
|
||||||
getExactAlarmStatus: function() {
|
// Battery/Power methods
|
||||||
return window.Capacitor.nativePromise('DailyNotification', 'getExactAlarmStatus', {});
|
getBatteryStatus: function() {
|
||||||
},
|
return cap.nativePromise('DailyNotification', 'getBatteryStatus', {});
|
||||||
openExactAlarmSettings: function() {
|
},
|
||||||
return window.Capacitor.nativePromise('DailyNotification', 'openExactAlarmSettings', {});
|
getPowerState: function() {
|
||||||
},
|
return cap.nativePromise('DailyNotification', 'getPowerState', {});
|
||||||
// Test methods
|
},
|
||||||
testAlarm: function(options) {
|
requestBatteryOptimizationExemption: function() {
|
||||||
return window.Capacitor.nativePromise('DailyNotification', 'testAlarm', options || {});
|
return cap.nativePromise('DailyNotification', 'requestBatteryOptimizationExemption', {});
|
||||||
|
},
|
||||||
|
// Exact alarm methods
|
||||||
|
getExactAlarmStatus: function() {
|
||||||
|
return cap.nativePromise('DailyNotification', 'getExactAlarmStatus', {});
|
||||||
|
},
|
||||||
|
openExactAlarmSettings: function() {
|
||||||
|
return cap.nativePromise('DailyNotification', 'openExactAlarmSettings', {});
|
||||||
|
},
|
||||||
|
// Test methods
|
||||||
|
testAlarm: function(options) {
|
||||||
|
return cap.nativePromise('DailyNotification', 'testAlarm', options || {});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Register plugin
|
||||||
|
cap.Plugins.DailyNotification = DailyNotification;
|
||||||
|
|
||||||
|
console.log('✅ DailyNotification plugin registered with', Object.keys(DailyNotification).length, 'methods');
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
console.log('Capacitor plugins file loaded - DailyNotification plugin registered');
|
// Register when DOM is ready or immediately if Capacitor is already available
|
||||||
|
if (document.readyState === 'loading') {
|
||||||
|
document.addEventListener('DOMContentLoaded', registerPlugin);
|
||||||
|
} else {
|
||||||
|
registerPlugin();
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user