13.07.2015 Views

Beginning Objective-C pdf - EBook Free Download

Beginning Objective-C pdf - EBook Free Download

Beginning Objective-C pdf - EBook Free Download

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 9: Writing an Application 317}return;// send the data asynchronously[client sendData: jsonData];Accessing Remote Address BooksNow that everything is in place to make an address book available to other instances of theapplication on the network, you need a way to actually connect to them from your own instance.The application will perform this task in three steps:• First, it will obtain a list of available services by sending the-availableServiceNames: message to its XPC service proxy object. This listwill then be displayed to users in a window.• When the user chooses a service, the application will ask its XPC proxy tomake a connection by sending it the -attachToRemoteAddressBookWithName:handler: message.• When the connection is made successfully, a new address book windowwill be presented and the list of people loaded asynchronously by sending-allPeople: to the XPC proxy. Similarly to the local address book, theaddress details will be obtained on demand as the user selects users fromthe master list.We’ll come back to the main application in a short while. For now, let’s concentrate on theimplementation inside the XPC service.Reaching OutYou already saw how the XPC service handled the -availableServiceNames: message inListing 9-20. Its counterpart, -connectToServiceWithName:replyHandler:, follows that inAPAddressBookBrowser.m. Open that file and add the method stub seen in Listing 9-52.Listing 9-52. The Stub Connection Method- (void) connectToServiceWithName: (NSString *) namereplyHandler: (void (^)(id, NSError *)) replyHandler{NSLog(@"Connecting to service named '%@'", name);__block NSNetService * selected = nil;// search individual domains -- look in "local" domain first, then any others// ...// if no local services were found, look in the other domains// ...// if none were found at all, send back an error// ...www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!