有人能解釋爲什麼我的應用程序崩潰,出現以下錯誤:IOS:暴跌64位設備
EXC_BAD_ACCESS(Code = 1, address= ...)
僅在64臺設備,就會出現此崩潰。我無法弄清楚。
- (NSString *)getIPAddress
{
NSString *address = nil;
struct ifaddrs *interfaces = NULL;
struct ifaddrs *temp_addr = NULL;
int success = 0;
// retrieve the current interfaces - returns 0 on success
success = getifaddrs(&interfaces);
if (success == 0)
{
// Loop through linked list of interfaces
temp_addr = interfaces;
while(temp_addr != NULL)
{
if(temp_addr->ifa_addr->sa_family == AF_INET)// crashes here
{
// Check if interface is en0 which is the wifi connection on the iPhone
if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"])
{
// Get NSString from C String
address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)]; // crash also here
}
}
temp_addr = temp_addr->ifa_next;
}
}
// Free memory
freeifaddrs(interfaces);
return address;
}
謝謝!
什麼是你的IOS構建SDK指向?最新?你也編譯arm64構建(s)或arm7,你有沒有嘗試使用應用程序的非64位構建? – ApolloSoftware
@AmitApollo:基礎SDK ios8.2,有效架構是arm64,arm7。在非64位設備中沒有崩潰。崩潰只能在64位設備中看到! – rishu1992