core-foundation

How can I find the path to a file in an application bundle (NSBundle) using C?

五迷三道 提交于 2019-11-30 04:42:30
问题 Is there a C API for finding the path to a file in an application bundle? I know that this can be done in Objective-C with the following syntax. NSString *path = [[NSBundle mainBundle] pathForResource:@"MyImage" ofType:@"bmp"]; Is there a corresponding function that I can call from C or C++ code, as well? 回答1: After Mike K pointed me in the right direction, I was able to retrieve the path to a file in an application bundle with the following code. // Get a reference to the main bundle

Why doesn't this simple CoreMIDI program produce MIDI output?

江枫思渺然 提交于 2019-11-29 22:24:32
Here is an extremely simple CoreMIDI OS X application that sends MIDI data. The problem is that it doesn't work. It compiles fine, and runs. It reports no errors, and does not crash. The Source created becomes visible in MIDI Monitor. However, no MIDI data comes out . Could somebody let me know what I'm doing wrong here? #include <CoreMIDI/CoreMIDI.h> int main(int argc, char *args[]) { MIDIClientRef theMidiClient; MIDIEndpointRef midiOut; MIDIPortRef outPort; char pktBuffer[1024]; MIDIPacketList* pktList = (MIDIPacketList*) pktBuffer; MIDIPacket *pkt; Byte midiDataToSend[] = {0x91, 0x3c, 0x40}

Is there a method to generate a standard 128bit GUID (UUID) on the Mac?

和自甴很熟 提交于 2019-11-29 21:33:47
Is there a built in function equivalent to .NET's Guid.NewGuid(); in Cocoa? My desire is to produce a string along the lines of 550e8400-e29b-41d4-a716-446655440000 which represents a unique identifier. UUIDs are handled in Core Foundation, by the CFUUID library. The function you are looking for is CFUUIDCreate . FYI for further searches: these are most commonly known as UUIDs, the term GUID isn't used very often outside of the Microsoft world. You might have more luck with that search term. Some code: For a string UUID, the following class method should do the trick: +(NSString*)UUIDString {

Converting plist to binary plist

时间秒杀一切 提交于 2019-11-29 19:46:15
Apple strongly recommends using the binary plist format when reading large XML-based data sets into iPhone apps. Among their reasoning is the fact that XML parsing is very taxing on the iPhone. However, this requires that files residing on the remote web server be converted first. For frequently-changing content, it is not acceptable to do this manually. If at all possible, I'd like to avoid having a web based app call the command line to perform the conversion (i.e., plutil). Are there publicly available algorithms to perform this conversion? Yes. All the plist code is part of CoreFoundation,

How to convert a classic HFS path into a POSIX path

你离开我真会死。 提交于 2019-11-29 18:06:34
I am reading old files that still use HFS style paths, such as VolumeName:Folder:File . I need to convert them into POSIX paths. I do not like to do string replacement as it is a bit tricky, nor do I want to invoke AppleScript or Shell operations for this task. Is there a framework function to accomplish this? Deprecation is not an issue. BTW, here's a solution for the inverse operation . A solution in Obj-C and Swift as category / extension of NSString / String . The unavailable kCFURLHFSPathStyle style is circumvented in the same way as in the linked question. Objective-C @implementation

OSX FSEventStreamEventFlags not working correctly

随声附和 提交于 2019-11-29 09:19:18
I am watching a directory for file system events. Everything seems to work fine with one exception. When I create a file the first time, it spits out that it was created. Then I can remove it and it says it was removed. When I go to create the same file again, I get both a created and removed flag at the same time. I obviously am misunderstanding how the flags are being set when the callback is being called. What is happening here? // // main.c // GoFSEvents // // Created by Kyle Cook on 8/22/13. // Copyright (c) 2013 Kyle Cook. All rights reserved. // #include <CoreServices/CoreServices.h>

Retained Core Foundation Property

落爺英雄遲暮 提交于 2019-11-29 07:48:45
问题 (Xcode 4.2, iOS 5, ARC ) I have some properties of Core Foundation (/Graphics) objects that should take ownership of their objects. Now in these Apple docs I found this: In OS X v10.6 and later, you can use the __attribute__ keyword to specify that a Core Foundation property should be treated like an Objective-C object for memory management: @property(retain) __attribute__((NSObject)) CFDictionaryRef myDictionary; Unfortunately I couldn't find any elaboration on this. I'm using this:

JavaScriptCore console.log

独自空忆成欢 提交于 2019-11-29 03:12:56
I've put together a very simple program that uses JavaScriptCore to evaluate JS: #import <CoreFoundation/CoreFoundation.h> #import <JavaScriptCore/JavaScriptCore.h> int main(int argc, const char * argv[]) { JSGlobalContextRef ctx = JSGlobalContextCreate(NULL); FILE *f = fopen(argv[1],"r"); char * buffer = malloc(10000000); fread(buffer,1,10000000,f); CFStringRef strs = CFStringCreateWithCString(NULL, buffer, kCFStringEncodingASCII); JSStringRef jsstr = JSStringCreateWithCFString(strs); JSValueRef result = JSEvaluateScript(ctx, jsstr, NULL, NULL, 0, NULL); double res = JSValueToNumber(ctx,

CFRunLoopRun() vs [NSRunLoop run]

那年仲夏 提交于 2019-11-29 01:27:41
I have an NSRunLoop object, to which I attach timers and streams. It works great. Stopping it is another story alltogether. I run the loop using [runLoop run] . If I try to stop the loop using CRunLoopStop([[NSRunLoop currentRunLoop] getCFRunLoop]) , the loop won't stop. If I start the loop using CRunLoopRun() instead, it works. I have also made sure that the call is made on the correct thread (the one running my custom run loop). I have debugged this with pthread_self() . I found a mailing list archive, where a developer said "don't bother using CRunLoopStop() if you started the loop using

NSUrlRequest: where an app can find the default headers for HTTP request?

不羁岁月 提交于 2019-11-29 00:22:25
Does anybody know where an iOS app can see the default headers that NSUrlRequest sets for an HTTP request? Just creating NSUrlRequest with "http://.." NSURL and then asking: [request allHTTPHeaderFields] returns an empty dictionary. But I know that for example "Accept-Encoding" is set to "gzip" . So I want to get all that fields and show them in a HTTP request demo. I've also tried to swizzle [NSMutableURLRequest setValue:forHTTPHeaderField:] , but it seems that it is not used by underlying API (NSURLRequest or NSURLConnection) to set those default fields I'm hunting for. I'm making just a