core-foundation

How do I get the currently connected network interface name using Cocoa or Foundation?

五迷三道 提交于 2019-12-17 10:57:15
问题 I need to know the network interface name of the currently connected network interface, as in en0 , lo0 and so on. Is there a Cocoa/Foundation function that is going to give me this information? 回答1: You can cycle through network interfaces and get their names, IP addresses, etc. #include <ifaddrs.h> // you may need to include other headers struct ifaddrs* interfaces = NULL; struct ifaddrs* temp_addr = NULL; // retrieve the current interfaces - returns 0 on success NSInteger success =

Using IOKit to return Mac's Serial number returns 4 extra characters

若如初见. 提交于 2019-12-13 12:19:26
问题 I'm playing with IOKit and have the following code, the general idea is to pass a platformExpert key to this small core foundation command line application and have it print the decoded string. The test case is "serial-number". The code below when run like: ./compiled serial-number Almost works but returns the last 4 characters of the serial number at the beginning of the string i.e. for an example serial such as C12D2JMPDDQX it would return DDQXC12D2JMPDDQX Any ideas? #include

Right way to use __attribute__((NSObject)) with ARC?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 04:42:04
问题 I just use CFNumber as a example,so it can be any type don't have a Fundation toll-free part! I just write some test code like this: typedef __attribute__((NSObject)) CFNumberRef MYNumberRef; int main(int argc, const char * argv[]) { @autoreleasepool { MYNumberRef ptr = NULL; double myDouble = 10.1; ptr = CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &myDouble); CFIndex count = CFGetRetainCount(ptr); } return 0; } It is very strange that the count is 2. But if I use CFNumberRef ,

what is the CFNotificationCenter callback function observer?

喜欢而已 提交于 2019-12-13 01:29:49
问题 I'm new to the CFNotificationCenter. I was reading the documentation at developer.apple and it says that in the CallbackFunction that observer is "an arbitrary value other than NULL that identifies the observer". Can the observer be an object so that I can access its methods inside the callback function? These are the parameters as shown in the documentation. void MyCallBack ( CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo );

RegisterEventHotKey from thread

懵懂的女人 提交于 2019-12-13 00:56:08
问题 I followed this awesome tutorial to set up a hotkey - http://dbachrach.com/blog/2005/11/program-global-hotkeys-in-cocoa-easily/ However I am doing this from a thread. So I suspect I need to run some kind of event loop. I have tried: WaitNextEvent - with the everyEvent argument set to 0 - I guessed on that one because I can't figure out where they define it here - https://developer.apple.com/legacy/library/documentation/AppleScript/Conceptual/AppleEvents/dispatch_aes_aepg/dispatch_aes_aepg

CFAutoRelease() -like behavior on iOS6

一世执手 提交于 2019-12-12 19:07:12
问题 I have a method that creates an ABRecordRef, sets its properties and returns the ref. I'm encountering a crash when I use CFAutoRelease because I need to support iOS <7. how would I go about to properly releasing this? -(ABRecordRef) myRecord{ ABRecordRef newRecord = ABPersonCreate(); //some setting here return CFAutoRelease(newRecord); //how to release here? } 回答1: For CoreFoundation references, I actually wouldn't release that reference in your myRecord method. Instead I would define the

Does ABPersonViewController CFRetain its displayedPerson ABRecordRef?

拥有回忆 提交于 2019-12-12 18:27:38
问题 ABRecordRef addressBookRecord = ...; ABNewPersonViewController *newPersonViewController = [[[ABNewPersonViewController alloc] init] autorelease]; newPersonViewController.newPersonViewDelegate = delegate; newPersonViewController.displayedPerson = addressBookRecord; Is it safe to CFRelease(addressBookRecord); ? Is there a standard CoreFoundation pattern around this I'm not aware of? 回答1: I don't think it's safe to call CFRelease. displayedPerson is defined as follows in the header. So,

Memory Management: NSString's stringWithCString:encoding:

半城伤御伤魂 提交于 2019-12-12 08:06:01
问题 Suppose I'm getting a C string from some function: char * mystring = SomeCFunction(...); And I own this string (I'm responsible for freeing it when I'm done). If, in Objective-C, I create an NSString * using: NSString * mynsstring = [NSString stringWithCString:mystring encoding:NSUTF8StringEncoding]; Am I still responsible for freeing the original C string? I'm assuming the answer is yes, but I can't find a definitive answer in the documentation - and the functionality of the opposite method

CFDictionaryCreate crashes in Xcode 8 swift 3

不想你离开。 提交于 2019-12-12 06:08:57
问题 I have the following code for retrieving and storing RSAkeydata fileprivate func retrieveAndStoreRSAKeyData(isPublic: Bool) throws -> CFData { var resultCode = noErr var result: CFData let value = { if isPublic { let t = self.publicTag print(t) } else { let s = self.privateTag print(s) } } var keyCallbacks = kCFTypeDictionaryKeyCallBacks var valueCallbacks = kCFTypeDictionaryValueCallBacks let keys = [Unmanaged.passUnretained(kSecClass).toOpaque(), Unmanaged.passUnretained

Getting unexpected Pixels from Raw Image

半世苍凉 提交于 2019-12-11 18:09:27
问题 I am trying to catch R, G and B from some pixels on a game scene. For this I have created a Bitmap image in Black & White. This image is first loaded on Init(), afterwards, every sprite movement is checked for it is really an available spot. The thing is that I am getting unexpected data at R, G and B. I tried two Bitmap images (8bit and 24bit). They both have only black and white pixels. But the r, g and b keep telling me these pixels are any other color. I think that the "no_of_channels"