Web Service(Chapter 28 of Cocoa Programming for Mac OS X)
1 #import "AppController.h"2 #define AWS_ID @"1CKE6MZ6S27EFQ458402"
3
4 @implementation AppController
5
6 - (id)init
7 {
8 self = ;
9 if (self) {
10 // Initialization code here.
11 }
12
13 return self;
14 }
15
16 - (IBAction)fetchBooks:(id)sender
17 {
18 ;
19
20 NSString *input = ;
21 NSString *searchString = ;
22 NSLog(@"searchString = %@", searchString);
23
24 NSString *urlString = [NSString stringWithFormat:
25 @"http://ecs.amazonaws.com/onca/xml?"
26 @"Service=AWSECommerceService&"
27 @"AWSAcccessKeyID=%@&"
28 @"Operation=ItemSearch&"
29 @"SearchIndex=Books&"
30 @"Keywords=%@&"
31 @"Version=20007-07-16", AWS_ID, searchString];
32 NSURL *url = ;
33 NSURLRequest *urlRequest = ;
34
35 NSData *urlData;
36 NSURLResponse *response;
37 NSError *error;
38 urlData = ;
39
40 if(!urlData)
41 {
42 NSAlert *alert = ;
43 ;
44 return;
45 }
46
47 ;
48 doc = [ initWithData:urlData options:0 error:&error];
49 NSLog(@"doc = %@", doc);
50 if (!doc)
51 {
52 NSAlert *alert = ;
53 ;
54 return;
55 }
56
57 ;
58 itemNodes = [ retain];
59 if (!itemNodes)
60 {
61 NSAlert *alert = ;
62 ;
63 return;
64 }
65
66 ;
67 ;
68 }
69
70 - (int)numberOfRowsInTableView:(NSTableView*)tv
71 {
72 return 0;
73 }
74
75 - (void)dealloc
76 {
77 ;
78 }
79
80 @end
页:
[1]