bzr branch
/browse/iphone/tappity
| Line | Revision | Contents |
| 1 | 46 | // |
| 2 | // tappityAppDelegate.m |
|
| 3 | // tappity |
|
| 4 | // |
|
| 5 | // Created by döme on 25.10.2009. |
|
| 6 | // Copyright __MyCompanyName__ 2009. All rights reserved. |
|
| 7 | // |
|
| 8 | ||
| 9 | #import "TappityAppDelegate.h" |
|
| 10 | 48 | |
| 11 | 46 | #import "BonjourBrowser.h" |
| 12 | #import "TappityClient.h" |
|
| 13 | #import "TappityView.h" |
|
| 14 | ||
| 15 | @implementation TappityAppDelegate |
|
| 16 | ||
| 17 | 49 | @synthesize window, settingsView, touchSwitch, compassSwitch, locationSwitch, accelerationSwitch, feedbackSwitch; |
| 18 | 46 | |
| 19 | ||
| 20 | - (void)applicationDidFinishLaunching:(UIApplication *)application |
|
| 21 | { |
|
| 22 | |
|
| 23 | tapClient = [[TappityClient alloc] init]; |
|
| 24 | ||
| 25 | browser = [[BonjourBrowser alloc] initForType: @"_tappity._tcp" |
|
| 26 | inDomain: @"local" |
|
| 27 | customDomains: nil // we won't save any additional domains added by the user |
|
| 28 | showDisclosureIndicators: NO |
|
| 29 | showCancelButton: YES]; |
|
| 30 | ||
| 31 | browser.delegate = self; |
|
| 32 | |
|
| 33 | // We want to let the user know that the services list is dynamic and always updating, even when there are no |
|
| 34 | // services currently found. |
|
| 35 | browser.searchingForServicesString = NSLocalizedString(@"Searching for web services", @"Searching for web services string"); |
|
| 36 | ||
| 37 | 49 | [self.window addSubview: settingsView]; |
| 38 | ||
| 39 | [window makeKeyAndVisible]; |
|
| 40 | } |
|
| 41 | ||
| 42 | - (IBAction) letsGo: (id) sender |
|
| 43 | { |
|
| 44 | [settingsView removeFromSuperview]; |
|
| 45 | |
|
| 46 | [tapClient setEnableAccelerometer: [accelerationSwitch isOn]]; |
|
| 47 | [tapClient setEnableCompass: [compassSwitch isOn]]; |
|
| 48 | [tapClient setEnableLocation: [locationSwitch isOn]]; |
|
| 49 | [tapClient setEnableFeedbackVideoDisplay: [feedbackSwitch isOn]]; |
|
| 50 | ||
| 51 | 46 | [self.window addSubview: [browser view]]; |
| 52 | } |
|
| 53 | ||
| 54 | ||
| 55 | - (NSString *)copyStringFromTXTDict:(NSDictionary *)dict which:(NSString*)which { |
|
| 56 | // Helper for getting information from the TXT data |
|
| 57 | NSData* data = [dict objectForKey:which]; |
|
| 58 | return data ? [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease] : nil; |
|
| 59 | } |
|
| 60 | ||
| 61 | - (void) bonjourBrowser:(BonjourBrowser*) theBrowser didResolveInstance:(NSNetService*)service |
|
| 62 | { |
|
| 63 | NSLog(@"found bonjour server"); |
|
| 64 | |
|
| 65 | if (service) |
|
| 66 | { |
|
| 67 | [tapClient connectToService: service]; |
|
| 68 | } |
|
| 69 | ||
| 70 | if (!tapView) |
|
| 71 | tapView = [[TappityView alloc] initWithFrame: [theBrowser view].frame]; |
|
| 72 | |
|
| 73 | tapView.tapClient = tapClient; |
|
| 74 | 47 | tapClient.delegate = tapView; |
| 75 | 46 | |
| 76 | [[theBrowser view] removeFromSuperview]; |
|
| 77 | |
|
| 78 | [self.window addSubview: tapView]; |
|
| 79 | |
|
| 80 | [[UIApplication sharedApplication] _addRecorder: tapClient]; |
|
| 81 | ||
| 82 | |
|
| 83 | return; |
|
| 84 | ||
| 85 | // Construct the URL including the port number |
|
| 86 | // Also use the path, username and password fields that can be in the TXT record |
|
| 87 | NSDictionary* dict = [[NSNetService dictionaryFromTXTRecordData:[service TXTRecordData]] retain]; |
|
| 88 | NSString *host = [service hostName]; |
|
| 89 | |
|
| 90 | NSString* user = [[self copyStringFromTXTDict:dict which:@"u"] retain]; |
|
| 91 | NSString* pass = [[self copyStringFromTXTDict:dict which:@"p"] retain]; |
|
| 92 | |
|
| 93 | NSString* portStr = [[NSString alloc] initWithString:@""]; |
|
| 94 | |
|
| 95 | // Note that [NSNetService port:] returns an NSInteger in host byte order |
|
| 96 | NSInteger port = [service port]; |
|
| 97 | if (port != 0 && port != 80) |
|
| 98 | portStr = [[NSString alloc] initWithFormat:@":%d",port]; |
|
| 99 | |
|
| 100 | NSString* path = [[[self copyStringFromTXTDict:dict which:@"path"] retain] autorelease]; |
|
| 101 | if (!path || [path length]==0) { |
|
| 102 | path = [[[NSString alloc] initWithString:@"/"] autorelease]; |
|
| 103 | } else if (![[path substringToIndex:1] isEqual:@"/"]) { |
|
| 104 | path = [[[NSString alloc] initWithFormat:@"/%@",path] autorelease]; |
|
| 105 | } |
|
| 106 | |
|
| 107 | NSString* string = [[NSString alloc] initWithFormat:@"http://%@%@%@%@%@%@%@", |
|
| 108 | user?user:@"", |
|
| 109 | pass?@":":@"", |
|
| 110 | pass?pass:@"", |
|
| 111 | (user||pass)?@"@":@"", |
|
| 112 | host, |
|
| 113 | portStr, |
|
| 114 | path]; |
|
| 115 | |
|
| 116 | NSURL *url = [[NSURL alloc] initWithString:string]; |
|
| 117 | [[UIApplication sharedApplication] openURL:url]; |
|
| 118 | |
|
| 119 | [url release]; |
|
| 120 | [string release]; |
|
| 121 | [portStr release]; |
|
| 122 | [pass release]; |
|
| 123 | [user release]; |
|
| 124 | [dict release]; |
|
| 125 | } |
|
| 126 | ||
| 127 | - (void)dealloc |
|
| 128 | { |
|
| 129 | [browser release]; |
|
| 130 | [window release]; |
|
| 131 | 49 | [touchSwitch release]; |
| 132 | [accelerationSwitch release]; |
|
| 133 | [locationSwitch release]; |
|
| 134 | [compassSwitch release]; |
|
| 135 | [feedbackSwitch release]; |
|
| 136 | [settingsView release]; |
|
| 137 | 46 | [super dealloc]; |
| 138 | } |
|
| 139 | ||
| 140 | ||
| 141 | @end |
Loggerhead 1.17 is a web-based interface for Bazaar branches