6.5 KiB
6.5 KiB
33. iOS App — Push Notifications, Biometrics, Voice Enrollment, Camera
meta: id: shieldai-unified-restructure-33 feature: shieldai-unified-restructure priority: P1 depends_on: [shieldai-unified-restructure-28, shieldai-unified-restructure-29, shieldai-unified-restructure-30, shieldai-unified-restructure-31, shieldai-unified-restructure-32] tags: [ios, swiftui, native-features, push, biometrics, camera, mobile]
objective:
- Implement native iOS features that differentiate the mobile experience: push notifications via APNs, biometric authentication, voice enrollment with audio recording, and camera integration for document scanning or QR codes.
deliverables:
iOS/ShieldAI/Services/PushNotificationService.swift— Push notification handling:- Registers for remote notifications with APNs
- Handles device token registration with backend (task 14)
- Processes incoming notifications in foreground and background
- Deep links to relevant screen based on notification payload
- Rich notification content (images, actions) via Notification Service Extension
iOS/ShieldAI/Services/BiometricAuthService.swift— Biometric authentication:- Evaluates Face ID / Touch ID availability
- Prompts for biometric authentication
- Stores credential in Keychain for biometric-protected access
- Fallback to device passcode
iOS/ShieldAI/Views/VoicePrint/RecordingView.swift— Voice recording UI:- Real-time waveform visualization using
AVAudioRecorder+CAShapeLayer - Record / stop / playback controls
- Duration timer
- Quality check (minimum duration, signal level)
- Submit enrollment to API
- Real-time waveform visualization using
iOS/ShieldAI/Views/Common/DocumentScannerView.swift— Document scanning:- Uses
VisionKitVNDocumentCameraViewController(iOS 13+) - Captures ID documents or property deeds
- OCR text extraction using
VNRecognizeTextRequest - Review and retake functionality
- Uses
iOS/ShieldAI/Services/CameraService.swift— Camera access wrapper:- Checks and requests camera/microphone permissions
- Handles permission denied states with guidance to Settings
iOS/ShieldAI/ShieldAI.entitlements— App entitlements:- Push notifications (
aps-environment) - Sign in with Apple (
com.apple.developer.applesignin) - Keychain sharing (if needed)
- Push notifications (
steps:
- Push Notifications:
- Add
UIApplicationDelegatemethods orUNUserNotificationCenterDelegate registerForRemoteNotifications()inShieldAIApp.swifton launchdidRegisterForRemoteNotificationsWithDeviceToken→ send token to backend viaapi.notification.registerDevicedidReceiveRemoteNotification→ parse payload, show local notification if in foreground- Handle notification tap: extract
screenandidfrom payload, navigate viaAppRouter - Create Notification Service Extension target for rich notifications (image attachments)
- Add
- Biometric Auth:
LAContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics)evaluatePolicywith localized reason: "Authenticate to access ShieldAI"- On success: unlock Keychain item containing refresh token
- On failure: show password fallback
- Add toggle in Settings to enable/disable biometric auth
- Voice Recording:
- Request microphone permission (
AVAudioSession.requestRecordPermission) - Configure
AVAudioSessionfor recording AVAudioRecorderwith.wavformat, 16kHz, mono- Real-time waveform: read
averagePower(forChannel:)in a timer, updatePathinCanvas - Minimum duration: 5 seconds
- On stop: playback with
AVAudioPlayer, then submit toapi.voiceprint.createEnrollment
- Request microphone permission (
- Document Scanner:
VNDocumentCameraViewControllerfor captureVNRecognizeTextRequestfor OCR on captured image- Display recognized text for user review
- Use for: ID verification, property deed upload, broker opt-out form scanning
- Camera Service:
- Centralized permission manager for camera and microphone
AVCaptureDevice.authorizationStatus(for: .video/audio)- Show explanatory UI before requesting permission
- Handle
.deniedand.restrictedstates
- Update
Info.plist:NSMicrophoneUsageDescription: "ShieldAI needs microphone access to enroll your voice for clone detection."NSCameraUsageDescription: "ShieldAI uses the camera to scan documents and verify your identity."NSFaceIDUsageDescription: "Use Face ID to securely access your ShieldAI account."UIBackgroundModes:remote-notification
- Test on physical device (simulator cannot test push notifications or biometrics accurately).
steps:
- Unit: BiometricAuthService returns correct availability state
- Unit: CameraService returns correct permission status
- Integration: Push token registration sends correct data to backend
- E2E: Receive test push notification and verify deep link navigation
- E2E: Record voice sample and submit enrollment successfully
- E2E: Scan document and verify OCR text extraction
acceptance_criteria:
- App registers for push notifications and sends device token to backend
- Incoming push notifications display correctly in foreground and background
- Tapping a notification deep links to the correct screen
- Face ID / Touch ID authentication works for app unlock
- Voice recording captures audio, shows waveform, and submits enrollment
- Document scanner captures images and extracts text via OCR
- All permission requests include explanatory descriptions
- Denied permissions show helpful guidance to Settings app
- Native features work on both iPhone and iPad
validation:
- Test push notifications using APNs test tool or Firebase Console
- Verify biometric auth on device with Face ID/Touch ID
- Record a 10-second voice sample and verify enrollment created in backend
- Scan a printed document and verify OCR text matches
- Run unit tests via Xcode Cmd+U
notes:
- Push notifications require an Apple Developer account and APNs certificate/key. For development, use the sandbox environment.
- The Notification Service Extension runs in a separate process and has limited memory (~24MB). Keep image processing lightweight.
- Voice recording quality matters for ML model accuracy. Use 16kHz mono WAV — this matches the web app's preprocessing pipeline.
- Document scanning with VisionKit is iOS 13+. For older versions, fall back to
UIImagePickerController. - Biometric auth should be optional. Users can always use password login.
- Consider adding a "Quick Actions" 3D Touch / Haptic Touch menu for common actions ("Run DarkWatch scan", "Check number").