Commit 0f0a34cd authored by Wei Han's avatar Wei Han

ios progress (need to test on physical device)

parent 4e255409
......@@ -119,14 +119,18 @@ export default function App() {
setStatuses(prev => ({ ...prev, [perm.key]: result }));
}
}
if (Platform.OS as string === 'ios') {
}
}
if (Platform.OS === 'ios') {
Alert.alert(
"Enable Caller ID",
"Go to Settings → Phone → Call Blocking & Identification and enable [Your App] to see caller ID labels."
"Go to Settings → Phone → Call Blocking & Identification and enable [Your App] to see caller ID labels.",
[
{ text: "Open Settings", onPress: () => Linking.openURL("app-settings:") },
{ text: "Cancel", style: "cancel" }
]
);
}
}
}
}, []);
useEffect(() => {
......@@ -141,6 +145,49 @@ export default function App() {
const allGranted = Object.values(statuses).every(s => s === RESULTS.GRANTED);
// --- iOS: Call Directory management ---
const checkCallDirectoryStatus = async () => {
if (Platform.OS !== "ios" || !CallDirectoryManager) {
console.warn("CallDirectoryManager not available on this platform");
return;
}
try {
const status = await CallDirectoryManager.getEnabledStatusForExtension(
"com.whoscall.app.CallDirectoryExtension" // <-- must match your extension bundle ID
);
console.log("Call Directory status:", status);
if (status === 2) {
Alert.alert("✅ Enabled", "Call Directory Extension is enabled");
} else {
Alert.alert(
"⚠️ Not Enabled",
"Go to Settings → Phone → Call Blocking & Identification and enable Whoscall."
);
}
} catch (e) {
console.error("Error checking Call Directory status:", e);
}
};
const reloadCallDirectory = async () => {
if (Platform.OS !== "ios" || !CallDirectoryManager) {
console.warn("CallDirectoryManager not available on this platform");
return;
}
try {
const success = await CallDirectoryManager.reloadExtension(
"com.whoscall.app.CallDirectoryExtension"
);
console.log("Reload result:", success);
if (success) {
Alert.alert("🔄 Reloaded", "Extension reloaded successfully");
}
} catch (e) {
console.error("Error reloading Call Directory:", e);
Alert.alert("❌ Reload Failed", String(e));
}
};
return (
<View style={styles.container}>
<Text style={styles.title}>Permissions Status</Text>
......@@ -158,6 +205,13 @@ export default function App() {
))}
{allGranted && <Text style={styles.granted}>All permissions granted ✅</Text>}
<Button title="Check Again" onPress={checkAllPermissions} />
{Platform.OS === "ios" && (
<>
<Button title="Check Call Directory Status" onPress={checkCallDirectoryStatus} />
<View style={{ height: 10 }} />
<Button title="Reload Call Directory" onPress={reloadCallDirectory} />
</>
)}
</View>
);
}
......
#import <React/RCTBridgeModule.h>
@interface RCT_EXTERN_MODULE(CallDirectoryManager, NSObject)
RCT_EXTERN_METHOD(getEnabledStatusForExtension:(NSString *)identifier
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(reloadExtension:(NSString *)identifier
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
@end
import Foundation
import CallKit
@objc(CallDirectoryManager)
class CallDirectoryManager: NSObject {
@objc
func getEnabledStatusForExtension(_ identifier: String,
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
let manager = CXCallDirectoryManager.sharedInstance
manager.getEnabledStatusForExtension(withIdentifier: identifier) { status, error in
if let error = error {
reject("E_STATUS", "Failed to get status: \(error.localizedDescription)", error)
return
}
resolve(status.rawValue) // 0 = unknown, 1 = disabled, 2 = enabled
}
}
@objc
func reloadExtension(_ identifier: String,
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
let manager = CXCallDirectoryManager.sharedInstance
manager.reloadExtension(withIdentifier: identifier) { error in
if let error = error {
reject("E_RELOAD", "Failed to reload: \(error.localizedDescription)", error)
} else {
resolve(true)
}
}
}
@objc static func requiresMainQueueSetup() -> Bool {
return false
}
}
This diff is collapsed.
......@@ -21,6 +21,8 @@ class CallDirectoryHandler: CXCallDirectoryProvider {
let vipNumbers: [(number: Int64, label: String)] = [
(60189884118, "Wei Yi"),
(60123456789, "Spam Caller"),
(60122553372, "Someone Else"),
(60123456789, "Scam Caller"),
]
for entry in vipNumbers {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment