Commit 501198d0 authored by Wei Han's avatar Wei Han Committed by alep

ios progress (need to test on physical device)

parent 7a905f79
...@@ -119,14 +119,18 @@ export default function App() { ...@@ -119,14 +119,18 @@ export default function App() {
setStatuses(prev => ({ ...prev, [perm.key]: result })); setStatuses(prev => ({ ...prev, [perm.key]: result }));
} }
} }
if (Platform.OS as string === 'ios') {
Alert.alert(
"Enable Caller ID",
"Go to Settings → Phone → Call Blocking & Identification and enable [Your App] to see caller ID labels."
);
}
} }
} }
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.",
[
{ text: "Open Settings", onPress: () => Linking.openURL("app-settings:") },
{ text: "Cancel", style: "cancel" }
]
);
}
}, []); }, []);
useEffect(() => { useEffect(() => {
...@@ -141,6 +145,49 @@ export default function App() { ...@@ -141,6 +145,49 @@ export default function App() {
const allGranted = Object.values(statuses).every(s => s === RESULTS.GRANTED); 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 ( return (
<View style={styles.container}> <View style={styles.container}>
<Text style={styles.title}>Permissions Status</Text> <Text style={styles.title}>Permissions Status</Text>
...@@ -158,6 +205,13 @@ export default function App() { ...@@ -158,6 +205,13 @@ export default function App() {
))} ))}
{allGranted && <Text style={styles.granted}>All permissions granted ✅</Text>} {allGranted && <Text style={styles.granted}>All permissions granted ✅</Text>}
<Button title="Check Again" onPress={checkAllPermissions} /> <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> </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 { ...@@ -21,6 +21,8 @@ class CallDirectoryHandler: CXCallDirectoryProvider {
let vipNumbers: [(number: Int64, label: String)] = [ let vipNumbers: [(number: Int64, label: String)] = [
(60189884118, "Wei Yi"), (60189884118, "Wei Yi"),
(60123456789, "Spam Caller"), (60123456789, "Spam Caller"),
(60122553372, "Someone Else"),
(60123456789, "Scam Caller"),
] ]
for entry in vipNumbers { for entry in vipNumbers {
...@@ -47,4 +49,4 @@ extension CallDirectoryHandler: CXCallDirectoryExtensionContextDelegate { ...@@ -47,4 +49,4 @@ extension CallDirectoryHandler: CXCallDirectoryExtensionContextDelegate {
NSLog("Call Directory extension error: \(error.localizedDescription)") NSLog("Call Directory extension error: \(error.localizedDescription)")
} }
} }
#endif #endif
\ No newline at end of file
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