2
// tappityAppDelegate.m
5
// Created by döme on 25.10.2009.
9
* Copyright (c) 2009 Doemoetoer Gulyas.
10
* All rights reserved.
12
* Redistribution and use in source and binary forms, with or without
13
* modification, are permitted provided that the following conditions
15
* 1. Redistributions of source code must retain the above copyright
16
* notice, this list of conditions and the following disclaimer.
17
* 2. Redistributions in binary form must reproduce the above copyright
18
* notice, this list of conditions and the following disclaimer in the
19
* documentation and/or other materials provided with the distribution.
20
* 3. The name of the author may not be used to endorse or promote products
21
* derived from this software without specific prior written permission.
23
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
#import "TappityAppDelegate.h"
37
#import "BonjourBrowser.h"
38
#import "TappityClient.h"
39
#import "TappityView.h"
41
static void catch_pipe(int sig_num)
43
signal(SIGPIPE, catch_pipe);
48
@implementation TappityAppDelegate
50
@synthesize window, settingsView, touchSwitch, compassSwitch, locationSwitch, accelerationSwitch, feedbackSwitch;
53
- (void) connectionWasTerminated: (SocketMessenger*) theMessenger
55
NSLog(@"connection dead, showing selection screen again");
56
[tapView removeFromSuperview];
57
[self.window addSubview: [browser view]];
60
- (void) setImage: (UIImage*) img
62
[tapView setImage: img];
64
- (void)applicationDidFinishLaunching:(UIApplication *)application
66
signal(SIGPIPE, catch_pipe);
68
tapClient = [[TappityClient alloc] init];
69
[tapClient setDelegate: self];
71
browser = [[BonjourBrowser alloc] initForType: @"_tappity._tcp"
73
customDomains: nil // we won't save any additional domains added by the user
74
showDisclosureIndicators: NO
75
showCancelButton: YES];
77
[browser setDelegate: self];
79
// We want to let the user know that the services list is dynamic and always updating, even when there are no
80
// services currently found.
81
browser.searchingForServicesString = NSLocalizedString(@"Searching for services", @"Searching for services string");
83
[self.window addSubview: settingsView];
85
[window makeKeyAndVisible];
88
- (IBAction) letsGo: (id) sender
90
[settingsView removeFromSuperview];
92
[tapClient setEnableAccelerometer: [accelerationSwitch isOn]];
93
[tapClient setEnableCompass: [compassSwitch isOn]];
94
[tapClient setEnableLocation: [locationSwitch isOn]];
95
[tapClient setEnableFeedbackVideoDisplay: [feedbackSwitch isOn]];
97
[self.window addSubview: [browser view]];
101
- (NSString *)copyStringFromTXTDict:(NSDictionary *)dict which:(NSString*)which {
102
// Helper for getting information from the TXT data
103
NSData* data = [dict objectForKey:which];
104
return data ? [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease] : nil;
107
- (void) bonjourBrowser:(BonjourBrowser*) theBrowser didResolveInstance:(NSNetService*)service
109
NSLog(@"found bonjour server");
113
[tapClient connectToService: service];
117
tapView = [[TappityView alloc] initWithFrame: [theBrowser view].frame];
119
tapView.tapClient = tapClient;
121
[[theBrowser view] removeFromSuperview];
123
[self.window addSubview: tapView];
125
[[UIApplication sharedApplication] _addRecorder: tapClient];
135
[touchSwitch release];
136
[accelerationSwitch release];
137
[locationSwitch release];
138
[compassSwitch release];
139
[feedbackSwitch release];
140
[settingsView release];
144
- (void)applicationWillTerminate:(UIApplication *)application
146
[tapClient terminateConnection];