//setup timer somewhere in the code [NSTimer scheduledTimerWithTimeInterval:5.0f target:self selector:@selector(onTimerEvent:)userInfo:nil repeats:NO]; - (void)onTimerEvent:(id)userInfo{ //Your code when timer fires }
"Do something when application terminated"
//in mainAppDelegate.m
- (void)applicationDidFinishLaunching:(UIApplication *)application {
//
//init code
//
atexit(applicationWillTerminate);
}
void applicationWillTerminate(){
//some stuff
}
//in mainAppDelegate.h
@interface mainAppDelegate : NSObject <UIApplicationDelegate> {
//.....
}
void applicationWillTerminate();
read more"Select image from library"
- (void)addAction:(id)sender{
// Set up the image picker controller and add it to the view
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePickerController animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[picker dismissModalViewControllerAnimated:YES];
//Save images in DB
MInsuranceImage ...
read more"Parse XML using iPhone SDK"
//
// XMLReader.h
#import <UIKit/UIKit.h>
@class MSearchItem;
@interface XMLReader : NSObject {
@private
MSearchItem *searchItemObj;
NSMutableString *_contentOfCurrentUserSession;
NSMutableArray *searchList;
}
@property (nonatomic, retain) MSearchItem *searchItemObj;
@property (nonatomic, retain) NSMutableString *contentOfCurrentUserSession;
@property (nonatomic, retain) NSMutableArray *searchList;
-(void)parseXMLFileAtURL:(NSURL *)URL parseXMLFile:(NSData *)fileData parseError:(NSError **)error;
@end
//
// XMLReader.m
#import "XMLReader.h"
#import ...
read more"Empty Database.m/h template for sqllite3"
//
// Database.h
#import <Foundation/Foundation.h>
#import <sqlite3.h>
@interface Database : NSObject {
sqlite3 *database;
NSString *dbPath;
}
+ (Database *)sharedDatabase;
- (void)createEditableCopyOfDatabaseIfNeeded;
- (void) openDb;
read more@end
//-----------------------------------------------------------------------------------------------------
// Database.m
#import "Database.h"
@implementation Database
static Database *_sharedDatabase;
BOOL dbOpen = NO;
+ (Database *)sharedDatabase
{
if (!_sharedDatabase) {
_sharedDatabase = [[Database alloc] init];
}
return _sharedDatabase;
}
// Creates a writable copy ...
"Create UIButton in runtime"
UIButton *registerButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
registerButton.frame = CGRectMake(80.0, 170, 150.0, 30.0);
[registerButton setTitle:@"From Contacts" forState:UIControlStateNormal];
[registerButton addTarget:self action:@selector(fromContactsAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:registerButton];
read more"Animate fade in/out"
IN *.m file
------------------------------
#pragma mark ANIMATION
//-------fade in
-(void)animateFadingIn{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
//set transformation
[UIView commitAnimations];
}
//-------fade out
- (void)animateFadingOut{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDidStopSelector:@selector(fadeAnimationDidStop:finished:context:)];
[UIView setAnimationDelegate:self];
//set transformation ...
read more"Get information from iPhone address book (only with emails)"
//Also you need to include AddressBook.framework
#import <AddressBook/AddressBook.h>
#import <AddressBook/ABAddressBook.h>
#import <AddressBook/ABPerson.h>
[contactList removeAllObjects];
// open the default address book.
ABAddressBookRef m_addressbook = ABAddressBookCreate();
if (!m_addressbook) {
NSLog(@"opening address book");
}
// can be cast to NSArray, toll-free
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(m_addressbook);
CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook);
// CFStrings ...
read more"Transformation in OpenGL (GL_MODELVIEW / GL_TEXTURE)"
glPushMatrix();
{
// - in MODEL MODE
//translate
glTranslatef(0.0, 0.0, 0.0);
//scale
glScalef(1.0, 1.0, 1.0);
//rotate
glRotatef(0.0, 0.0, 0.0, 0.0);
glMatrixMode( GL_TEXTURE );
glPushMatrix();
{
// - in TEXTURE MODE
//translate
glTranslatef(0.0, 0.0, 0.0);
//scale
glScalef(1.0, 1.0 ...
read more"Get application options"
BOOL isSomething = [[NSUserDefaults standardUserDefaults] boolForKey:@"enabled_something"];
NSInteger someIntValue = [[NSUserDefaults standardUserDefaults] integerForKey:@"some_integer"];
read more