samdmarshall / SDMMobileDevice

MobileDevice Implementation
BSD 3-Clause "New" or "Revised" License
574 stars 97 forks source link

SDMMD_AMDeviceCopyValue on non existing key crashes on swift #89

Closed ttys42 closed 8 years ago

ttys42 commented 8 years ago

I'm getting an EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP) crash when trying to use SDMMD_AMDeviceCopyValue with a key on a device which does not support the key (like phone number on iPod) Running the code in objective-c will cause a console log but no crash while using the code below in swift will cause the crash.

var result1: sdmmd_return_t = SDMMD_AMDeviceConnect(deviceRef)
var result2 = SDMMD_AMDeviceStartSession(deviceRef)

var key = CFStringCreateWithCString(kCFAllocatorDefault, kPhoneNumber, 0)
var pn = SDMMD_AMDeviceCopyValue(deviceRef, kGlobalDomain, key)
print(pn.takeUnretainedValue())

var result3 = SDMMD_AMDeviceStopSession(device)
var result4 = SDMMD_AMDeviceDisconnect(device)

Call in obj-c NSLog(@"%@",(NSString*)CFBridgingRelease(SDMMD_AMDeviceCopyValue(device, NULL, CFSTR(kPhoneNumber))));

samdmarshall commented 8 years ago

Where does the crash trace place the issue? If this is into swift then there is nothing I can do about it. Due to this not happening in objective-c I am leaning towards saying this is not the fault of my library.

ttys42 commented 8 years ago

You're right - the trace showed a problem in swift not in your library. Sorry for any confusion and keep up the good work!

samdmarshall commented 8 years ago

You should be opening an issue on this with the swift team, I'm not sure if it is improper usage of the API or an actual problem with swift though.