commit affb5d2255cf8a2370ee8cd6d3c26648e1c35c87
parent 4c2427a7697d1a6d9094f4da3877060bf9d62261
Author: Kyle Milz <kyle@getaddrinfo.net>
Date: Sat, 13 Jun 2015 15:15:54 -0600
ios: commit wip
Diffstat:
6 files changed, 161 insertions(+), 46 deletions(-)
diff --git a/ios/Makefile b/ios/Makefile
@@ -5,20 +5,26 @@
#
CC=clang
-CFLAGS=-isysroot /var/sdks/Latest.sdk
+CFLAGS=-isysroot /var/sdks/iPhoneOS7.1.sdk
LDFLAGS=-framework Foundation -framework UIKit
-OBJS=main.o TestLabel.o
+PROG=shlist
+OBJS=main.o ViewController.o
.SUFFIXES: .m .o
-Shist: $(OBJS)
+$(PROG): $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $@
+ cp $@ /Applications/$(PROG).App/
+ killall -HUP SpringBoard
.m.o:
$(CC) $(CFLAGS) -c $<
-$(OBJS): TestLabel.h
+$(OBJS): ViewController.h
+
+open:
+ open net.iphonedevwiki.shlist
clean:
- rm -f *.o Shist
+ rm -f *.o $(PROG)
diff --git a/ios/TestLabel.h b/ios/TestLabel.h
@@ -1,5 +0,0 @@
-#import <UIKit/UIKit.h>
-
-@interface TestLabel : UILabel
--(instancetype)initWithBackgroundColor:(UIColor *)backgroundColor;
-@end
diff --git a/ios/TestLabel.m b/ios/TestLabel.m
@@ -1,15 +0,0 @@
-#import "TestLabel.h"
-
-@implementation TestLabel
--(instancetype)initWithBackgroundColor:(UIColor *)backgroundColor
-{
- if(self == [self init])
- {
- self.backgroundColor = backgroundColor;
- self.textColor = UIColor.whiteColor;
- self.text = @"rofl";
- self.frame = CGRectMake(20,20,300,300);
- }
- return self;
-}
-@end
diff --git a/ios/ViewController.h b/ios/ViewController.h
@@ -0,0 +1,10 @@
+#import <UIKit/UIKit.h>
+
+@interface ViewController : UIViewController <NSStreamDelegate>
+
+-(IBAction)showMessage;
+
+@end
+
+NSInputStream *inputStream;
+NSOutputStream *outputStream;
diff --git a/ios/ViewController.m b/ios/ViewController.m
@@ -0,0 +1,57 @@
+#import "ViewController.h"
+
+@interface ViewController ()
+
+@end
+
+@implementation ViewController
+
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+ // Do any additional setup after loading the view, typically from a nib.
+
+ [self showMessage];
+ [self initNetworkCommunication];
+}
+
+- (void)viewDidUnload
+{
+ [super viewDidUnload];
+ // Release any retained subviews of the main view.
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
+}
+
+- (IBAction)showMessage
+{
+ UIAlertView *helloWorldAlert = [[UIAlertView alloc]
+ initWithTitle:@"My First App" message:@"Hello, World!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
+
+ // Display the Hello World Message
+ [helloWorldAlert show];
+}
+
+- (void)initNetworkCommunication
+{
+ CFReadStreamRef readStream;
+ CFWriteStreamRef writeStream;
+
+ CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"absentmindedproductions.ca", 5437, &readStream, &writeStream);
+ inputStream = (NSInputStream *)readStream;
+ outputStream = (NSOutputStream *)writeStream;
+
+ [inputStream setDelegate:self];
+ [outputStream setDelegate:self];
+
+ [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
+ [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
+
+ [inputStream open];
+ [outputStream open];
+}
+
+@end
diff --git a/ios/main.m b/ios/main.m
@@ -1,33 +1,95 @@
#import <UIKit/UIKit.h>
-#import "TestLabel.h"
+#import "ViewController.h"
+
+@class ViewController;
-@interface TestAppDelegate : UIResponder <UIApplicationDelegate>
+@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (nonatomic, strong) UIWindow *window;
+@property (strong, nonatomic) ViewController *viewController;
@end
int main(int argc, char *argv[])
{
- @autoreleasepool
- {
- return UIApplicationMain(argc, argv, nil, NSStringFromClass(TestAppDelegate.class));
- }
+ @autoreleasepool
+ {
+ return UIApplicationMain(argc, argv, nil, NSStringFromClass(AppDelegate.class));
+ }
}
-
-@implementation TestAppDelegate
-@synthesize window=_window;
-
+
+@implementation AppDelegate
+
+@synthesize window = _window;
+@synthesize viewController = _viewController;
+
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
- self.window = [UIWindow.alloc initWithFrame:UIScreen.mainScreen.bounds];
- self.window.backgroundColor = UIColor.redColor;
-
- UILabel *label = [[TestLabel alloc] initWithBackgroundColor:self.window.backgroundColor];
- [self.window addSubview:label];
- [label release];
-
- [self.window makeKeyAndVisible];
-
- return true;
+
+ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+ // Override point for customization after application launch.
+ self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
+ self.window.rootViewController = self.viewController;
+ [self.window makeKeyAndVisible];
+ return YES;
+
+ /*
+ self.window = [UIWindow.alloc initWithFrame:UIScreen.mainScreen.bounds];
+ self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
+ self.window.rootViewController = self.viewController;
+
+ self.window.backgroundColor = UIColor.redColor;
+
+ UILabel *label = [[TestLabel alloc] initWithBackgroundColor:self.window.backgroundColor];
+ [self.window addSubview:label];
+ [label release];
+
+ [self.window makeKeyAndVisible];
+
+ return YES;
+ */
}
-
+
+- (void)applicationWillResignActive:(UIApplication *)application
+{
+ // Sent when the application is about to move from active to inactive
+ // state. This can occur for certain types of temporary interruptions
+ // (such as an incoming phone call or SMS message) or when the user
+ // quits the application and it begins the transition to the background
+ // state.
+ //
+ // Use this method to pause ongoing tasks, disable timers, and throttle
+ // down OpenGL ES frame rates. Games should use this method to pause the
+ // game.
+}
+
+- (void)applicationDidEnterBackground:(UIApplication *)application
+{
+ // Use this method to release shared resources, save user data,
+ // invalidate timers, and store enough application state information to
+ // restore your application to its current state in case it is
+ // terminated later.
+ //
+ // If your application supports background execution, this method is
+ // called instead of applicationWillTerminate: when the user quits.
+}
+
+- (void)applicationWillEnterForeground:(UIApplication *)application
+{
+ // Called as part of the transition from the background to the inactive
+ // state; here you can undo many of the changes made on entering the
+ // background.
+}
+
+- (void)applicationDidBecomeActive:(UIApplication *)application
+{
+ // Restart any tasks that were paused (or not yet started) while the
+ // application was inactive. If the application was previously in the
+ // background, optionally refresh the user interface.
+}
+
+- (void)applicationWillTerminate:(UIApplication *)application
+{
+ // Called when the application is about to terminate. Save data if
+ // appropriate. See also applicationDidEnterBackground:.
+}
+
@end