2
// tappityAppDelegate.m
5
// Created by döme on 25.10.2009.
6
// Copyright __MyCompanyName__ 2009. All rights reserved.
9
#import "TappityAppDelegate.h"
10
#import "TappityViewController.h"
11
#import "BonjourBrowser.h"
12
#import "TappityClient.h"
13
#import "TappityView.h"
15
@implementation TappityAppDelegate
18
@synthesize viewController;
21
- (void)applicationDidFinishLaunching:(UIApplication *)application
24
tapClient = [[TappityClient alloc] init];
26
browser = [[BonjourBrowser alloc] initForType: @"_tappity._tcp"
28
customDomains: nil // we won't save any additional domains added by the user
29
showDisclosureIndicators: NO
30
showCancelButton: YES];
32
browser.delegate = self;
34
// We want to let the user know that the services list is dynamic and always updating, even when there are no
35
// services currently found.
36
browser.searchingForServicesString = NSLocalizedString(@"Searching for web services", @"Searching for web services string");
38
// Add the controller's view as a subview of the window
39
[self.window addSubview: [browser view]];
41
// [window addSubview:viewController.view];
42
[window makeKeyAndVisible];
47
- (NSString *)copyStringFromTXTDict:(NSDictionary *)dict which:(NSString*)which {
48
// Helper for getting information from the TXT data
49
NSData* data = [dict objectForKey:which];
50
return data ? [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease] : nil;
53
- (void) bonjourBrowser:(BonjourBrowser*) theBrowser didResolveInstance:(NSNetService*)service
55
NSLog(@"found bonjour server");
59
[tapClient connectToService: service];
63
tapView = [[TappityView alloc] initWithFrame: [theBrowser view].frame];
65
tapView.tapClient = tapClient;
67
[[theBrowser view] removeFromSuperview];
69
[self.window addSubview: tapView];
71
[[UIApplication sharedApplication] _addRecorder: tapClient];
76
// Construct the URL including the port number
77
// Also use the path, username and password fields that can be in the TXT record
78
NSDictionary* dict = [[NSNetService dictionaryFromTXTRecordData:[service TXTRecordData]] retain];
79
NSString *host = [service hostName];
81
NSString* user = [[self copyStringFromTXTDict:dict which:@"u"] retain];
82
NSString* pass = [[self copyStringFromTXTDict:dict which:@"p"] retain];
84
NSString* portStr = [[NSString alloc] initWithString:@""];
86
// Note that [NSNetService port:] returns an NSInteger in host byte order
87
NSInteger port = [service port];
88
if (port != 0 && port != 80)
89
portStr = [[NSString alloc] initWithFormat:@":%d",port];
91
NSString* path = [[[self copyStringFromTXTDict:dict which:@"path"] retain] autorelease];
92
if (!path || [path length]==0) {
93
path = [[[NSString alloc] initWithString:@"/"] autorelease];
94
} else if (![[path substringToIndex:1] isEqual:@"/"]) {
95
path = [[[NSString alloc] initWithFormat:@"/%@",path] autorelease];
98
NSString* string = [[NSString alloc] initWithFormat:@"http://%@%@%@%@%@%@%@",
102
(user||pass)?@"@":@"",
107
NSURL *url = [[NSURL alloc] initWithString:string];
108
[[UIApplication sharedApplication] openURL:url];
120
[viewController release];