一般来说,我对 iPhone 开发和 XCode 比较陌生,不知道如何开始对 CoreTelephony 问题进行故障排除。我来自 Java 背景,所以内存管理和指针对我来说有点生疏,而且更复杂的是,我上次查看 iPhone 项目时,Objective-C 要求您在卸载时释放对象,这似乎已经改变了?
我正在尝试在概念验证应用程序中使用库:CoreTelephony.h、CoreTelephony.m 来获取手机的 imei 号码。
代码片段:
// 为 Web 视图请求 Web 应用程序 url 的代码 [appView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:fullURL]]];
// Code to call apple's private core telephony framework
NSString *imei;
_CTServerConnectionCopyMobileIdentity(result, sc, &imei);
代码在以下位置引发 Thread 1:EXC_BAD_ACCESS (code=13, address=0x0) 错误:_CTServerConnectionCopyMobileIdentity(result, sc, &imei);
任何帮助将不胜感激。
CoreTelephony.h 代码:
//
struct CTServerConnection
{
int a;
int b;
CFMachPortRef myport;
int c;
int d;
int e;
int f;
int g;
int h;
int i;
};
struct CTResult
{
int flag;
int a;
};
struct CTServerConnection * _CTServerConnectionCreate(CFAllocatorRef, void *, int *);
void _CTServerConnectionCopyMobileIdentity(struct CTResult *, struct CTServerConnection *, NSString **);
堆栈转储:
OS Version: iOS 6.0 (10A403)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 CoreTelephony 0x35c4ff46 0x35c14000 + 245574
1 CoreTelephony 0x35c5012a 0x35c14000 + 246058
2 AttendanceMonitor 0x00026c9e 0x24000 + 11422
3 UIKit 0x36282590 0x36260000 + 140688
4 UIKit 0x362c2d74 0x36260000 + 404852
5 UIKit 0x362beae8 0x36260000 + 387816
6 UIKit 0x363001cc 0x36260000 + 655820
7 AttendanceMonitor 0x000265e0 0x24000 + 9696
8 UIKit 0x362c3ad4 0x36260000 + 408276
9 UIKit 0x362c365e 0x36260000 + 407134
10 UIKit 0x362bb846 0x36260000 + 374854
11 UIKit 0x36263c3c 0x36260000 + 15420
12 UIKit 0x362636d0 0x36260000 + 14032
13 UIKit 0x3626311e 0x36260000 + 12574
14 GraphicsServices 0x343db5a0 0x343d5000 + 26016
15 GraphicsServices 0x343db1ce 0x343d5000 + 25038
16 CoreFoundation 0x33700170 0x33669000 + 618864
17 CoreFoundation 0x33700112 0x33669000 + 618770
18 CoreFoundation 0x336fef94 0x33669000 + 614292
19 CoreFoundation 0x33671eb8 0x33669000 + 36536
20 CoreFoundation 0x33671d44 0x33669000 + 36164
21 UIKit 0x362ba480 0x36260000 + 369792
22 UIKit 0x362b72fc 0x36260000 + 357116
23 AttendanceMonitor 0x00025ba4 0x24000 + 7076
24 libdyld.dylib 0x382f6b1c 0x382f5000 + 6940
Thread 1:
0 libsystem_kernel.dylib 0x323fad98 0x323e9000 + 73112
1 libsystem_c.dylib 0x377accf6 0x377a6000 + 27894
2 libsystem_c.dylib 0x377aca12 0x377a6000 + 27154
3 libsystem_c.dylib 0x377ac8a0 0x377a6000 + 26784
Thread 2 name: Dispatch queue: com.apple.libdispatch-manager
Thread 2:
0 libsystem_kernel.dylib 0x323ea648 0x323e9000 + 5704
1 libdispatch.dylib 0x37b134ec 0x37b02000 + 70892
2 libdispatch.dylib 0x37b05df4 0x37b02000 + 15860