iOS 11中如何通过CallHistory.framework及私有框架获取通话记录?
Hey Jeff, let's break down your two questions about accessing call history on iOS 11:
First off, let's be clear: CallHistory.framework is a private Apple framework, so any app relying on it won't pass App Store review. That said, if you're building for internal use, testing, or non-distribution scenarios, here's how you can work with it:
Step 1: Dynamically load the private framework
The framework is located at/System/Library/PrivateFrameworks/CallHistory.framework. Since it's not part of the public SDK, you need to load it at runtime usingdlopen:void* frameworkHandle = dlopen("/System/Library/PrivateFrameworks/CallHistory.framework/CallHistory", RTLD_NOW); if (!frameworkHandle) { NSLog(@"Failed to load framework: %s", dlerror()); return; }Step 2: Access the core class and fetch records
The primary class for retrieving call history isCHManager. You can reference it viaobjc_getClassand call its private methods. For iOS 11, the method to fetch recent calls is typicallyrecentCallsWithLimit:offset::Class CHManagerClass = objc_getClass("CHManager"); id manager = [[CHManagerClass alloc] init]; // Fetch the last 100 call records NSArray* callRecords = [manager performSelector:NSSelectorFromString(@"recentCallsWithLimit:offset:") withObject:@(100) withObject:@(0)];Step 3: Handle privacy permissions
Even with the framework loaded, you need user consent to access call history. Add theNSCallUsageDescriptionkey to yourInfo.plistwith a clear explanation of why your app needs this data—otherwise, the system will block permission requests.Key Caveats
- Private APIs are undocumented, so method signatures could break with minor iOS 11 updates.
- Sandbox restrictions will block access unless your app is signed with appropriate entitlements or runs on a jailbroken device.
Yes, you can—but the approach depends on whether the target device is jailbroken, and there are important risks to consider:
For Jailbroken iOS 11 Devices
- No sandbox barriers: Jailbreaking removes Apple's sandbox constraints, so your app can freely load private frameworks and access system data without special entitlements.
- Distribution: You can share the app via Cydia, sideload it directly using tools like
scpor file managers like Filza. - Risks: Jailbreak compatibility varies by tool and iOS 11 subversion, and jailbroken devices have reduced security.
For Non-Jailbroken iOS 11 Devices
- Enterprise Signing: You'll need an Apple Enterprise Developer account to sign your app. Enterprise-signed apps can be sideloaded onto devices without App Store review.
- Entitlements: Add the
com.apple.coretelephony.callhistory.readentitlement to your provisioning profile. Note that Apple may revoke your enterprise certificate if they detect misuse of private APIs. - User Consent: Users still need to grant permission via the system prompt, triggered by your
NSCallUsageDescriptionentry inInfo.plist.
General Risks
- API Instability: Private frameworks aren't supported by Apple, so even a small iOS 11 update could break your app's call history retrieval.
- Security & Policy: Accessing private system data exposes your app to vulnerabilities, and Apple actively blocks apps that misuse private APIs—even those distributed outside the App Store.
内容的提问来源于stack exchange,提问作者Jeff




