fix(ios): add comprehensive error handling and timeout for permission check
Enhanced permission check with better debugging: Error Handling Improvements: - Added 10-second timeout to detect if promise never resolves - Added method existence check before calling - Added promise validation (checks if result is actually a promise) - Added detailed console logging at each step - Added result validation (checks if result is null/undefined) Debugging Features: - Logs plugin availability and method types - Logs promise type and result structure - Logs all error details (message, type, stack) - Shows available methods if checkPermissionStatus is missing Fixes: - Status stuck on 'Checking permissions...' - Better error messages to diagnose issues - Timeout prevents infinite waiting Result: Should now show either permission status or clear error message
This commit is contained in:
@@ -355,22 +355,64 @@
|
||||
function checkPermissions() {
|
||||
console.log('🔐 checkPermissions called');
|
||||
console.log('🔐 Plugin available:', !!window.DailyNotification);
|
||||
console.log('🔐 Plugin object:', window.DailyNotification);
|
||||
console.log('🔐 checkPermissionStatus method:', typeof window.DailyNotification?.checkPermissionStatus);
|
||||
|
||||
const status = document.getElementById('status');
|
||||
status.innerHTML = '🔐 Checking permissions...';
|
||||
status.style.background = 'rgba(255, 255, 0, 0.3)'; // Yellow background
|
||||
|
||||
// Add timeout to detect if promise never resolves
|
||||
const timeoutId = setTimeout(() => {
|
||||
console.error('❌ Permission check timed out after 10 seconds');
|
||||
status.innerHTML = '❌ Permission check timed out<br>Check console for details.';
|
||||
status.style.background = 'rgba(255, 0, 0, 0.3)'; // Red background
|
||||
}, 10000);
|
||||
|
||||
try {
|
||||
if (!window.DailyNotification) {
|
||||
clearTimeout(timeoutId);
|
||||
console.error('❌ DailyNotification plugin not available');
|
||||
status.innerHTML = '❌ DailyNotification plugin not available<br>Check console for details.';
|
||||
status.style.background = 'rgba(255, 0, 0, 0.3)'; // Red background
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof window.DailyNotification.checkPermissionStatus !== 'function') {
|
||||
clearTimeout(timeoutId);
|
||||
console.error('❌ checkPermissionStatus is not a function');
|
||||
console.error('❌ Available methods:', Object.keys(window.DailyNotification));
|
||||
status.innerHTML = '❌ checkPermissionStatus method not found<br>Available methods: ' + Object.keys(window.DailyNotification).join(', ');
|
||||
status.style.background = 'rgba(255, 0, 0, 0.3)'; // Red background
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('🔐 Calling checkPermissionStatus...');
|
||||
window.DailyNotification.checkPermissionStatus()
|
||||
const promise = window.DailyNotification.checkPermissionStatus();
|
||||
console.log('🔐 Promise returned:', promise);
|
||||
console.log('🔐 Promise type:', typeof promise);
|
||||
|
||||
if (!promise || typeof promise.then !== 'function') {
|
||||
clearTimeout(timeoutId);
|
||||
console.error('❌ checkPermissionStatus did not return a promise');
|
||||
status.innerHTML = '❌ checkPermissionStatus did not return a promise<br>Check console for details.';
|
||||
status.style.background = 'rgba(255, 0, 0, 0.3)'; // Red background
|
||||
return;
|
||||
}
|
||||
|
||||
promise
|
||||
.then(result => {
|
||||
clearTimeout(timeoutId);
|
||||
console.log('✅ Permission status result:', result);
|
||||
console.log('✅ Result type:', typeof result);
|
||||
console.log('✅ Result keys:', result ? Object.keys(result) : 'null');
|
||||
|
||||
if (!result) {
|
||||
status.innerHTML = '❌ Permission check returned null<br>Check console for details.';
|
||||
status.style.background = 'rgba(255, 0, 0, 0.3)'; // Red background
|
||||
return;
|
||||
}
|
||||
|
||||
status.innerHTML = `🔐 Permission Status:<br>
|
||||
Notifications: ${result.notificationsEnabled ? '✅ YES' : '❌ NO'}<br>
|
||||
Exact Alarm: ${result.exactAlarmEnabled ? '✅ YES' : '❌ NO'}<br>
|
||||
@@ -380,13 +422,20 @@
|
||||
'rgba(0, 255, 0, 0.3)' : 'rgba(255, 165, 0, 0.3)'; // Green or orange
|
||||
})
|
||||
.catch(error => {
|
||||
clearTimeout(timeoutId);
|
||||
console.error('❌ Permission check error:', error);
|
||||
status.innerHTML = `❌ Permission check failed:<br>${error.message || error}`;
|
||||
console.error('❌ Error type:', typeof error);
|
||||
console.error('❌ Error message:', error?.message);
|
||||
console.error('❌ Error stack:', error?.stack);
|
||||
status.innerHTML = `❌ Permission check failed:<br>${error?.message || error || 'Unknown error'}`;
|
||||
status.style.background = 'rgba(255, 0, 0, 0.3)'; // Red background
|
||||
});
|
||||
} catch (error) {
|
||||
clearTimeout(timeoutId);
|
||||
console.error('❌ Permission check exception:', error);
|
||||
status.innerHTML = `❌ Permission check failed:<br>${error.message || error}`;
|
||||
console.error('❌ Exception type:', typeof error);
|
||||
console.error('❌ Exception message:', error?.message);
|
||||
status.innerHTML = `❌ Permission check failed:<br>${error?.message || error || 'Unknown error'}`;
|
||||
status.style.background = 'rgba(255, 0, 0, 0.3)'; // Red background
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user