iOS SDK không cho phép ứng dụng tự động nghe cuộc gọi đến (auto-answer) bằng public API.
Tại sao không thể?
- Quyền riêng tư & bảo mật: Cuộc gọi là tương tác người dùng chủ động
- Apple không cung cấp public API để kiểm soát Call UI / accept call
- Vi phạm App Store Review Guidelines Section 2.5.1 (Private API)
Private API (Chỉ tham khảo, KHÔNG dùng production)
// Private API - SẼ BỊ REJECT APP STORE
// CTCallAnswer(call); // từ CoreTelephony framework (private)
// Hoặc dùng CallKit private methods
Giải pháp hợp pháp thay thế
1. CallKit - Tích hợp VoIP app với hệ thống gọi
Nếu xây dựng app VoIP (Zalo, Viber, Messenger...), dùng CallKit:
- Hiển thị native call UI (fullscreen incoming call screen)
- User tự nhấn "Accept" / "Decline" trên system UI
- Tích hợp với lock screen, CarPlay, Apple Watch
- Support "Auto-answer" chỉ khi user bật trong Settings → Accessibility → Touch → Call Audio Routing → Auto-Answer Calls
import CallKit
// Report incoming call
let provider = CXProvider(configuration: CXProviderConfiguration(localizedName: "MyApp"))
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .phoneNumber, value: "+84901234567")
update.hasVideo = false
provider.reportNewIncomingCall(with: UUID(), update: update) { error in }
2. User tự bật Auto-Answer (Accessibility)
User có thể tự bật: Cài đặt → Phụ trợ → Chạm → Định tuyến âm thanh cuộc gọi → Tự động trả lời. App không thể bật/tắt giúp user.
3. Push Notification + CallKit
Server gửi VoIP Push (PushKit) → App nhận → Report incoming call via CallKit → User nhấn Accept.
Kết luận
Không có cách nào auto-answer call bằng code public API. Chỉ có thể:
- Dùng CallKit hiển thị native call UI để user tự nghe
- Hướng dẫn user bật Accessibility Auto-Answer (nếu phù hợp use case)
- Không dùng Private API - chắc chắn reject App Store