fix(test-app): iOS permission handling and build improvements

- Add BGTask identifiers and background modes to iOS Info.plist
- Fix permission method calls (checkPermissionStatus vs checkPermissions)
- Implement Android-style permission checking pattern
- Add "Request Permissions" action card with check-then-request flow
- Fix simulator selection in build script (use device ID for reliability)
- Add Podfile auto-fix to fix-capacitor-plugins.js
- Update build documentation with unified script usage

Fixes:
- BGTask registration errors (Info.plist missing identifiers)
- Permission method not found errors (checkPermissions -> checkPermissionStatus)
- Simulator selection failures (now uses device ID)
- Podfile incorrect pod name (TimesafariDailyNotificationPlugin -> DailyNotificationPlugin)

The permission flow now matches Android: check status first, then show
system dialog if needed. iOS system dialog appears automatically when
requestNotificationPermissions() is called.

Files changed:
- test-apps/daily-notification-test/ios/App/App/Info.plist (new)
- test-apps/daily-notification-test/src/lib/typed-plugin.ts
- test-apps/daily-notification-test/src/views/HomeView.vue
- test-apps/daily-notification-test/scripts/build.sh (new)
- test-apps/daily-notification-test/scripts/fix-capacitor-plugins.js
- test-apps/daily-notification-test/docs/BUILD_QUICK_REFERENCE.md
- test-apps/daily-notification-test/README.md
- test-apps/daily-notification-test/package.json
- test-apps/daily-notification-test/package-lock.json
This commit is contained in:
Matthew
2025-11-20 23:05:49 -08:00
parent e6cd8eb055
commit cebf341839
9 changed files with 1142 additions and 30 deletions

View File

@@ -22,6 +22,7 @@ const __dirname = path.dirname(__filename);
const PLUGINS_JSON_PATH = path.join(__dirname, '../android/app/src/main/assets/capacitor.plugins.json');
const SETTINGS_GRADLE_PATH = path.join(__dirname, '../android/capacitor.settings.gradle');
const PODFILE_PATH = path.join(__dirname, '../ios/App/Podfile');
const PLUGIN_ENTRY = {
name: "DailyNotification",
@@ -103,6 +104,98 @@ ${correctPath}`
}
}
/**
* Fix iOS Podfile to use correct plugin pod name and path
*/
function fixPodfile() {
console.log('🔧 Verifying iOS Podfile...');
if (!fs.existsSync(PODFILE_PATH)) {
console.log(' Podfile not found (iOS platform may not be added yet)');
return;
}
try {
let content = fs.readFileSync(PODFILE_PATH, 'utf8');
const originalContent = content;
// The correct pod reference should be:
// pod 'DailyNotificationPlugin', :path => '../../node_modules/@timesafari/daily-notification-plugin/ios'
const correctPodLine = "pod 'DailyNotificationPlugin', :path => '../../node_modules/@timesafari/daily-notification-plugin/ios'";
// Check if Podfile already has the correct reference
if (content.includes("pod 'DailyNotificationPlugin'")) {
// Check if path is correct
if (content.includes('@timesafari/daily-notification-plugin/ios')) {
console.log('✅ Podfile has correct DailyNotificationPlugin reference');
} else {
// Fix the path
console.log('⚠️ Podfile has DailyNotificationPlugin but wrong path - fixing...');
content = content.replace(
/pod ['"]DailyNotificationPlugin['"].*:path.*/,
correctPodLine
);
// Also fix if it's using the wrong name (TimesafariDailyNotificationPlugin)
content = content.replace(
/pod ['"]TimesafariDailyNotificationPlugin['"].*:path.*/,
correctPodLine
);
if (content !== originalContent) {
fs.writeFileSync(PODFILE_PATH, content);
console.log('✅ Fixed DailyNotificationPlugin path in Podfile');
}
}
} else if (content.includes("TimesafariDailyNotificationPlugin")) {
// Fix wrong pod name
console.log('⚠️ Podfile uses wrong pod name (TimesafariDailyNotificationPlugin) - fixing...');
content = content.replace(
/pod ['"]TimesafariDailyNotificationPlugin['"].*:path.*/,
correctPodLine
);
if (content !== originalContent) {
fs.writeFileSync(PODFILE_PATH, content);
console.log('✅ Fixed pod name in Podfile (TimesafariDailyNotificationPlugin -> DailyNotificationPlugin)');
}
} else {
// Add the pod reference if it's missing
console.log('⚠️ Podfile missing DailyNotificationPlugin - adding...');
// Find the capacitor_pods function or target section
if (content.includes('def capacitor_pods')) {
// Add after capacitor_pods function
content = content.replace(
/(def capacitor_pods[\s\S]*?end)/,
`$1\n\n # Daily Notification Plugin\n ${correctPodLine}`
);
} else if (content.includes("target 'App'")) {
// Add in target section
content = content.replace(
/(target 'App' do)/,
`$1\n ${correctPodLine}`
);
} else {
// Add at end before post_install
content = content.replace(
/(post_install)/,
`${correctPodLine}\n\n$1`
);
}
if (content !== originalContent) {
fs.writeFileSync(PODFILE_PATH, content);
console.log('✅ Added DailyNotificationPlugin to Podfile');
}
}
} catch (error) {
console.error('❌ Error fixing Podfile:', error.message);
// Don't exit - iOS might not be set up yet
}
}
/**
* Run all fixes
*/
@@ -112,9 +205,10 @@ function fixAll() {
fixCapacitorPlugins();
fixCapacitorSettingsGradle();
fixPodfile();
console.log('\n✅ All fixes applied successfully!');
console.log('💡 These fixes will persist until the next "npx cap sync android"');
console.log('💡 These fixes will persist until the next "npx cap sync"');
}
// Run if called directly
@@ -122,4 +216,4 @@ if (import.meta.url === `file://${process.argv[1]}`) {
fixAll();
}
export { fixCapacitorPlugins, fixCapacitorSettingsGradle, fixAll };
export { fixCapacitorPlugins, fixCapacitorSettingsGradle, fixPodfile, fixAll };