open knowledge sessions

Toko 17 – iPhone Programming

At March 7th, 2010 there will be an OpenToko workshop about iPhone Programming.

Leo van der Veen created the c74 App. c74 is an iPhone app that let’s you connect your device with Cycling ’74’s Max/MSP 5 and create custom layouts which can be operated directly from your iPhone. (read more…). In this OpenToko Leo will share his expertise on designing and programming applications for the iPhone. He will be covering the Objective-C programming language, XCode, Interface Builder and how to install your application on your iPhone.

In the second part of the workshop Rick Companje will explain about programming in C++ for the iPhone using OpenFrameworks. More information about OpenFrameworks for the iPhone can be found on this website.

This OpenToko is “hands-on”. If you want to join this OpenToko please bring your own laptop running Mac OSX (Leopard Mac OS X 10.5.5 or higher) that is capable of having the iPhone SDK installed on it. If you do not have the iPhone SDK yet, please go to http://developer.apple.com/iphone and register for free to download the SDK.

At the end of the day all participants will give a short demonstration about their results.

Date: March 7th, 2010 @ 10:00
Location: Kleine Koppel 40, 3812 PH Amersfoort

If you have never visited a Toko before, please read the about page. If you want to join, fill out the registration form.

Notes

Notes for OpenToko on iPhone Programming
First talk by Leo van der Veen, creater of the c74 app.

Getting started

1. Download and Install iPhone SDK
2. Start XCode
3. New Project
4. For iPhone
5. New View based App
6. Build and Run in Simulator
Leo started explaining about the different filetypes in XCode like .framework, .m, .h, .xib, .plist, .app and more.
m-files are source files for your classes. h-files are the header files for your classes. xib files are for interface builder. With interfacebuilder you can design your application’s interface by dragging Buttons etc.

Keyboard shortcuts

- toggle between header and source file: Alt+Cmd+Up-arrow
- open the debugger console by: Ctrl+Cmd+R
- find info in the reference about a class/function etc by Alt+doubleclick (ie. UIWebView)
- during codehinting you can press Escape to get more hints.

….AppDelegate.h

- import UIKit.h
- @interface seems to be the equivalent of a class
- NSObject is the mother of all objects
- AppDelegate implements UIApplicationDelegate

…ViewController.h

- extends UIViewController
- IBOutlet = interface builder outlet. In the header file you can declare pointers to the components in the interface builder. This is recognized by inteface builder. You then can link them to eachother by Ctrl+dragging in interface builder and setting the File’s Owner. This is quite unintuitive and you have to get used to this.
- IBAction = interface builder action: -(IBAction)sliderChanged:(id)sender;

NSString

- Strings are surrounded by double quotes and are preceded by the @-sign. This seems to be a shortcut to the NSString object.
- NSString stringWithFormat (is formatString)
- NSString *data = [NSString swtringWithFormat:@"gps %f ....", ....")

Syntax highlighting and codehinting

- XCode has code hinting. This helps you by completing the names of functions, classes etc. All functions will be highlighted in blue. When something does not get blue you probably made a typo.

Variables

int someInt = 5;
float someFloat = 5.5;
NSString *text = @"klaas";

Functions / methods

- call a C-function ie. NSLog(@"jeuj!"); //normal brackets with parameter
Example of calling the NSLog function with a printf like syntax:
-(void) printMe: (NSString *)what
{
...
NSLog(@"%@ %@ %@ %i %f",what,klaas,@"Rick",someInt,someFloat);
}
- You can have 'properties' which kind of a getter/setter construction.
- In your header file use @property(readwrite,retain)NSString *myProp;
- In your sourcecode file use @synthesize myProp; to intiantiate
- To set a property of an object you can use Objective-C notation or plain C.
- Objective C: [myWebView setDelegate:self];
- Plain C: myWebView.delegate = self;

Defining a class

- This way you define a class:
@interface OpenTokoViewController : UIViewController
<UIWebViewDelegate, UITableViewDataSource, UITableViewDelegate>
- You don't need to declare methods in a header file when these are already defined in the a superclass. Your own methods you have to declare. ie.
 -(void) printMe:(NSString *) what;
- You can call the superclass function of a function in the subclass. ie. [super viewDidLoad];
Arrays
-This way to create array with strings. You can put any type in an array and also mix them.
myArray = [[NSArray alloc]initWithObjects:@"Jan",@"Klaas",@"Piet",@"Hein",@"Florus",nil];
- There is also NSDictionary which can be compared to a hashtable.
- To call a function loadRequest on the myWebView object with one NSURLRequest parameter do the following:
[myWebView loadRequest:[
  NSURLRequest requestWithURL:[
    NSURL URLWithString:@"http://www.opentoko.org"]
  ]
];

Delegates and NotificationCenter

- Delegation = one object can 'inform' another object about something.
- You can use "#pragma mark WebView delegate" but I forgot what it is for.
- the 'id' parametertype of a delegate can be of any type. You can cast this type to the original type ie. (UIView*).
- Example of an IBAction (called by the items designed in the interface builder):
-(IBAction)sliderChanged:(UISlider*)sender {//instead (UISlider*) you can use "id" if you don't now the parameter type. 
  NSLog(@"slider value = %f", sender.value); //[sender value]
}
- with the NSNotificationCenter multiple objects can receive notifications (with a unique name) send through the whole application.

GPS, Accelerometer and Compas

- CLLocationmanager gives access to the GPS in your iPhone.
- locationManager startUpdatingLocation, ditUpdateToLocation, from Location, longitude, lattitude, altitude and speed.
- UIAccelerometer 'sharedAccelerometer': didAccelerate, accelaration.x,y,z
- Compas:
- locationManager headingAvailable: startUpdatingHeading/stop...

Frameworks (ie. Audio)

For some classes you have to import certain Frameworks. You can do this by adding a .Framework file to your 'Groups & Files' panel. ie. AudioToolbox for sound. After adding the framework file you have to #import it in your header. To test this you can try the AudioServicesPlayAlertSound(kSystemSoundID_Vibrate); function which makes your iPhone vibrate for a sec.

Icons and Splashscreen

- To add and icon to your app create a 57x57px PNG and add this as 'existing file' to your project. Then set the filename of this icon in your application's .plist file.
- To add a splashscreen create a Default.png and add this as 'existing file' to your project.

UIView and Interface Builder

- All visual objects in your design view have UIView as superclass. You can programmatically create your own visual objects by extending the UIView.
- UIView has initWithFrame for its dimensions
- All UIView subclasses need a (void)drawRect function.
- Some events: touchesBegan, touchesCancelled, touchesEnded, touchesMoved. It can handle 11 fingers at the same time right?
UITouch *touch = [touches anyObject]
CGPoint = [touch locationInView:self];
NSLog(@"%f %f", point.x,point.y)
- setNeedsDisplay can be compared with updateDisplayList.
- CGRect is a C(++) struct. CGRectMake is a class: rectangle. x,y,w,h. CG means CoreGraphics.
- You can create multiple 'views' in interfacebuilder.
----------

OpenFrameworks for iPhone

After Leo's talk, Rick showed how to use the OpenFrameworks (C++) distribution for iPhone. General conclusion is that OpenFrameworks can be a very nice alternative for programming in Objective-C but more UI components need to be wrapped by OpenFrameworks addons to make it complete.

Flash CS5 for iPhone

Erik showed how to publish in Flash CS5 for the iPhone. This still has some limitations (like speed and filesize) but would be great if Apple and Adobe would work together on this.

Slides of iPhone Course @ Leiden University

A few weeks after the iPhone OpenToko, Rick Companje, Bas Haring and Edwin van der Heide gave two public lectures at Leiden University about programming for the iPhone. The slides of this presentation are available in Dutch.

9 Responses

  1. companje on 25-02-2010 at 10:12

    Peter: I’m learning Cacao Touch and Objective-C at the moment (from the book Beginning iPhone 3 Development). This because I’m planning to design and build a app together with a class mate. So I’m most interested in pitfalls when you want to design and build iPhone apps. And maybe some general overviews, because there are way to many topics to discuss to go in-depth.

  2. companje on 25-02-2010 at 10:12

    Florus: I like to learn the basic knowledge creating a simple iPhone app. Besides that it would be awesome to get the feeling what’s possible with OPENGL functions within the iPhone SDK.

  3. companje on 02-03-2010 at 16:10

    Diederick: …. Het lijkt mij echt ideaal als iemand kan uitleggen hoe je een basic iphone applicatie opzet zonder alle ‘guibuilder’ smuck. ….

  4. companje on 02-03-2010 at 16:10

    Sylvain: General info on iPhone programming and the differences and the advantages of OF vs ihone SDK.

  5. Florus on 08-03-2010 at 05:27

    Awesome day! Liked all the approaches to develop apps in different ways. With OpenFrameworks for instants it becomes interesting for apps that don’t necessary needs the GUI. And develop in C++ instead of Obj-C.
    Thanks to all contributors and speakers!

  6. companje on 08-03-2010 at 06:53

    Joris: Was leuk gisteren…!
    ook leuk: http://bambuser.com/channel/iConf/broadcast/605378
    vanaf minuut 39 begint een lezing over user interface design en hoe het de gebruiker makkelijker maken op de iphone
    erg interressant voor iedereen denk ik die er zondag was

  7. companje on 09-03-2010 at 07:14

    Annebeth: http://www.smashingmagazine.com/2010/03/03/how-to-market-your-mobile-app/#more-30864

  8. Joeri on 12-03-2010 at 14:46

    Heeft iemand de Flash CS5 beta?

  9. 3komma14 Notes » Blog Archive » Gratis iPhone programmeercursus on 15-04-2010 at 06:26

    [...] Teven vind je hier hele veel bruikbare info om een goede start te maken. opentoko.org [...]

© opentoko.org Proudly Powered by WordPress. Theme Untitled I Designed by Ruby Entries (RSS) and Comments (RSS).