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
|
||||
// This file registers the DailyNotification plugin for iOS
|
||||
// Methods bridge to native Swift implementation via Capacitor's native bridge
|
||||
|
||||
window.Capacitor = window.Capacitor || {};
|
||||
window.Capacitor.Plugins = window.Capacitor.Plugins || {};
|
||||
|
||||
// Register DailyNotification plugin with method stubs
|
||||
// Methods will be bridged to native Swift implementation
|
||||
window.Capacitor.Plugins.DailyNotification = window.Capacitor.Plugins.DailyNotification || {
|
||||
// Permission methods
|
||||
checkPermissionStatus: function() {
|
||||
return window.Capacitor.nativePromise('DailyNotification', 'checkPermissionStatus', {});
|
||||
},
|
||||
requestNotificationPermissions: function() {
|
||||
return window.Capacitor.nativePromise('DailyNotification', 'requestNotificationPermissions', {});
|
||||
},
|
||||
checkPermissions: function() {
|
||||
return window.Capacitor.nativePromise('DailyNotification', 'checkPermissions', {});
|
||||
},
|
||||
requestPermissions: function() {
|
||||
return window.Capacitor.nativePromise('DailyNotification', 'requestPermissions', {});
|
||||
},
|
||||
// Notification methods
|
||||
scheduleDailyNotification: function(options) {
|
||||
return window.Capacitor.nativePromise('DailyNotification', 'scheduleDailyNotification', options || {});
|
||||
},
|
||||
getNotificationStatus: function() {
|
||||
return window.Capacitor.nativePromise('DailyNotification', 'getNotificationStatus', {});
|
||||
},
|
||||
cancelAllNotifications: function() {
|
||||
return window.Capacitor.nativePromise('DailyNotification', 'cancelAllNotifications', {});
|
||||
},
|
||||
// Status methods
|
||||
checkStatus: function() {
|
||||
return window.Capacitor.nativePromise('DailyNotification', 'checkStatus', {});
|
||||
},
|
||||
// Channel methods
|
||||
isChannelEnabled: function(options) {
|
||||
return window.Capacitor.nativePromise('DailyNotification', 'isChannelEnabled', options || {});
|
||||
},
|
||||
openChannelSettings: function(options) {
|
||||
return window.Capacitor.nativePromise('DailyNotification', 'openChannelSettings', options || {});
|
||||
},
|
||||
// Configuration methods
|
||||
configure: function(options) {
|
||||
return window.Capacitor.nativePromise('DailyNotification', 'configure', options || {});
|
||||
},
|
||||
configureNativeFetcher: function(options) {
|
||||
return window.Capacitor.nativePromise('DailyNotification', 'configureNativeFetcher', options || {});
|
||||
},
|
||||
// Battery/Power methods
|
||||
getBatteryStatus: function() {
|
||||
return window.Capacitor.nativePromise('DailyNotification', 'getBatteryStatus', {});
|
||||
},
|
||||
getPowerState: function() {
|
||||
return window.Capacitor.nativePromise('DailyNotification', 'getPowerState', {});
|
||||
},
|
||||
requestBatteryOptimizationExemption: function() {
|
||||
return window.Capacitor.nativePromise('DailyNotification', 'requestBatteryOptimizationExemption', {});
|
||||
},
|
||||
// Exact alarm methods
|
||||
getExactAlarmStatus: function() {
|
||||
return window.Capacitor.nativePromise('DailyNotification', 'getExactAlarmStatus', {});
|
||||
},
|
||||
openExactAlarmSettings: function() {
|
||||
return window.Capacitor.nativePromise('DailyNotification', 'openExactAlarmSettings', {});
|
||||
},
|
||||
// Test methods
|
||||
testAlarm: function(options) {
|
||||
return window.Capacitor.nativePromise('DailyNotification', 'testAlarm', options || {});
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
// Wait for Capacitor to be available
|
||||
function registerPlugin() {
|
||||
if (!window.Capacitor) {
|
||||
setTimeout(registerPlugin, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
const cap = window.Capacitor;
|
||||
if (!cap.Plugins) {
|
||||
cap.Plugins = {};
|
||||
}
|
||||
|
||||
// Create plugin object with methods that call native bridge
|
||||
const DailyNotification = {
|
||||
// Permission methods
|
||||
checkPermissionStatus: function() {
|
||||
return cap.nativePromise('DailyNotification', 'checkPermissionStatus', {});
|
||||
},
|
||||
requestNotificationPermissions: function() {
|
||||
return cap.nativePromise('DailyNotification', 'requestNotificationPermissions', {});
|
||||
},
|
||||
checkPermissions: function() {
|
||||
return cap.nativePromise('DailyNotification', 'checkPermissions', {});
|
||||
},
|
||||
requestPermissions: function() {
|
||||
return cap.nativePromise('DailyNotification', 'requestPermissions', {});
|
||||
},
|
||||
// Notification methods
|
||||
scheduleDailyNotification: function(options) {
|
||||
return cap.nativePromise('DailyNotification', 'scheduleDailyNotification', options || {});
|
||||
},
|
||||
getNotificationStatus: function() {
|
||||
return cap.nativePromise('DailyNotification', 'getNotificationStatus', {});
|
||||
},
|
||||
cancelAllNotifications: function() {
|
||||
return cap.nativePromise('DailyNotification', 'cancelAllNotifications', {});
|
||||
},
|
||||
// Status methods
|
||||
checkStatus: function() {
|
||||
return cap.nativePromise('DailyNotification', 'checkStatus', {});
|
||||
},
|
||||
// Channel methods
|
||||
isChannelEnabled: function(options) {
|
||||
return cap.nativePromise('DailyNotification', 'isChannelEnabled', options || {});
|
||||
},
|
||||
openChannelSettings: function(options) {
|
||||
return cap.nativePromise('DailyNotification', 'openChannelSettings', options || {});
|
||||
},
|
||||
// Configuration methods
|
||||
configure: function(options) {
|
||||
return cap.nativePromise('DailyNotification', 'configure', options || {});
|
||||
},
|
||||
configureNativeFetcher: function(options) {
|
||||
return cap.nativePromise('DailyNotification', 'configureNativeFetcher', options || {});
|
||||
},
|
||||
// Battery/Power methods
|
||||
getBatteryStatus: function() {
|
||||
return cap.nativePromise('DailyNotification', 'getBatteryStatus', {});
|
||||
},
|
||||
getPowerState: function() {
|
||||
return cap.nativePromise('DailyNotification', 'getPowerState', {});
|
||||
},
|
||||
requestBatteryOptimizationExemption: function() {
|
||||
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