- 博客(32)
- 收藏
- 关注
原创 Presenting a local notification immediately while running in the background
- (void)applicationDidEnterBackground:(UIApplication *)application { NSLog(@"Application entered background state."); // bgTask is a property of the class NSAssert(self.bgTask == UII
2014-08-30 19:40:32 753
原创 Creating, configuring, and scheduling a local notification
- (void)scheduleNotificationWithItem:(ToDoItem *)item interval:(int)minutesBefore { NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; NSDateComponents *dateComps = [[NSDateComp
2014-08-30 19:34:09 740
原创 Monitoring the death of a parent process (via Dispatch Sources)
void MonitorParentProcess() { pid_t parentPID = getppid(); dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_source_t source = dispatc
2014-08-29 17:20:45 643
原创 Installing a block to monitor signals (via Dispatch Sources)
void InstallSignalHandler() { // Make sure the signal does not terminate the application. signal(SIGHUP, SIG_IGN); dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_
2014-08-29 17:09:13 1017
原创 Watching for filename changes (via Dispatch Sources)
an example that monitors a file for name changes and performs some custom behavior whenit does. (You would provide the actual behavior in place of theMyUpdateFileNamefunction called in theexample.
2014-08-29 16:57:12 715
原创 Reading /(Writing) Data from / (to) a Descriptor (Dispatch Sources)
dispatch_source_t ProcessContentsOfFile(const char* filename) { // Prepare the file for reading. int fd = open(filename, O_RDONLY); if (fd == -1) return NULL; fcntl(fd, F
2014-08-29 16:47:58 568
原创 Getting data from a dispatch source
FunctionDescriptiondispatch_source_-get_handleThis function returns the underlying system data type that the dispatch sourcemanages.For a descriptor dis
2014-08-29 16:18:42 507
原创 Creating a timer dispatch source
dispatch_source_t CreateDispatchTimer(uint64_t interval, uint64_t leeway, dispatch_queue_t queue, dispatch_block_t block) { dispatch_source_t tim
2014-08-29 16:17:45 1262
原创 Dispatch Sources
About Dispatch SourcesA dispatch sourceis a fundamental data type that coordinates the processing of specific low-level systemevents. Grand Central Dispatch supports the following types of dispatc
2014-08-29 15:21:49 569
原创 Waiting on Groups of Queued Tasks (dispatch_group_async)
// Waiting on asynchronous tasks dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);dispatch_group_t group = dispatch_group_create();// Add a task to the grou
2014-08-29 14:47:45 824
原创 Using Dispatch Semaphores to Regulate the Use of Finite Resources
The semantics for using a dispatch semaphore are as follows:When you create the semaphore (using thedispatch_semaphore_createfunction), you can specifya positive integer indicating the numbe
2014-08-29 14:42:29 651
原创 Performing Loop Iterations Concurrently
Original:for (i = 0; i < count; i++) { printf("%u\n",i);}Replacement:dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);dispatch_apply(count, queue,
2014-08-29 14:37:38 484
原创 Performing a Completion Block When a Task Is Done (!!!)
Executing a completion callback after a task
2014-08-29 14:03:15 597
原创 Adding a Single Task to a Queue
The following example shows how to use the block-based variants for dispatching tasks asynchronously and synchronously: dispatch_queue_t myCustomQueue;myCustomQueue = dispatch_queue_create("com.exa
2014-08-29 13:59:02 432
原创 Storing Custom Context Information with a Queue
Storing Custom Context Information with a QueueAll dispatch objects (including dispatch queues) allow you to associate custom context data with the object.To set and get this data on a given object,
2014-08-29 13:52:19 553
原创 Creating an NSInvocationOperation Object / NSBlockOperation Object
@implementation MyCustomClass - (NSOperation*)taskWithData:(id)data {NSInvocationOperation* theOp = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(myTaskMethod:) object:data]
2014-08-29 10:09:28 540
原创 Reading the contents of a file using POSIX functions
- (NSData*)readDataFromFileAtURL:(NSURL*)anURL { NSString* filePath = [anURL path]; fd = open([filePath UTF8String], O_RDONLY); if (fd == -1)return nil; NSMutableData* theData = [[[NS
2014-08-28 15:12:58 669
原创 Reading the contents of a file using NSFileHandle
- (NSData*)readDataFromFileAtURL:(NSURL*)anURL { NSFileHandle* aHandle = [NSFileHandle fileHandleForReadingFromURL:anURLerror:nil]; NSData* fileContents = nil; if (aHandle) fileCo
2014-08-28 14:57:51 1023
原创 Reading the bytes from a text file using a dispatch I/O channel
- (void)readContentsOfFile:(NSURL*)anURL { // Open the channel for reading. NSString* filePath = [anURL path]; self.channel = dispatch_io_create_with_path(DISPATCH_IO_RANDOM,
2014-08-28 14:42:43 1185
原创 How to create a custom directory for app files inside the ~/Library/Application Support directory.
- (NSURL*)applicationDirectory { NSString* bundleID = [[NSBundle mainBundle] bundleIdentifier];Managing Files and DirectoriesCreating New Files and Directories Programmatically NSFil
2014-08-28 14:03:35 958
原创 Filters Limit the File Types That the User Can Select
- (IBAction)askUserForImage:(id)sender { NSOpenPanel* panel = [NSOpenPanel openPanel]; // Let the user select any images supported by // the NSImage class. NSArray* imageTypes = [NSImag
2014-08-28 13:56:05 699
原创 Saving a file with a new type
- (void)exportDocument:(NSString*)name toType:(NSString*)typeUTI{ NSWindow* window = [[[self windowControllers] objectAtIndex:0] window]; // Build a new name for the file using the curren
2014-08-28 13:54:13 751
原创 Presenting the open panel to the user
- (IBAction)openExistingDocument:(id)sender { NSOpenPanel* panel = [NSOpenPanel openPanel]; // This method displays the panel and returns immediately. // The completion handler is called when
2014-08-28 13:48:14 591
原创 Retrieving the list of items in a directory all at once
NSURL *url = ;NSError *error = nil;NSArray *properties = [NSArray arrayWithObjects: NSURLLocalizedNameKey, NSURLCreationDateKey, NSURLLocalizedTypeDescriptionKey,nil];NSA
2014-08-28 11:24:31 526
原创 Looking for files that have been modified recently
NSString *directoryPath = ;NSDirectoryEnumerator *directoryEnumerator = [[NSFileManager defaultManager]enumeratorAtPath:directoryPath];NSDate *yesterday = [NSDate dateWithTimeIntervalSinceNow:(-60*
2014-08-28 11:18:03 741
转载 iOS进程间通讯(私有) CPDistributedMessagingCenter
Server:-(id)init... {... CPDistributedMessagingCenter *messagingCenter; // Center name must be unique, recommend using application identifier. messagingCenter = [CPDistributedMessagingCenter
2014-08-26 09:21:55 3895
原创 Notification Centers
Cocoa includes two types of notification centers:The NSNotificationCenter class manages notifications within a single process.The NSDistributedNotificationCenter class manages notifications
2014-08-25 15:39:15 432
原创 笔记1
1. Cocoa does not use getName because methods that start with “get” in Cocoa indicate that the method will return values by reference.
2014-08-25 08:59:20 437
转载 iOS Reverse Engineering Resources
http://samdmarshall.com/re.htmlReverse Engineering ResourcesDebuggingThese are very important guides for understanding the debugging process and how applications work.Mac OS X Debu
2014-08-13 16:41:31 657
原创 Manage your team in iOS/OS X enterprise development:
Manage your team in iOS/OS X enterprise development:Link: WWDC2014: 705_hd_distributing_enterprise_apps.movSummary:Enroll in iOS Developer Enterprise Program;Agent and Admins sho
2014-08-12 15:23:42 488
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人