Call selectors from your code. Create own buttons

by alex 26. May 2010 08:32

///////////////////BUTON

//-- button.h file

@interface MyButton : NSObject {

id receiver;

SEL selector;

}

 

 

//-- button.m file

-(void)addTarget:(id)target action:(SEL)action{

receiver = target;

selector =  action;

}

 

-(void)touch{

if (receiver) {

[receiver performSelector:selector];

}

}

 

//////////////////RECEIVER 

//-- receiver.m file

 

...

MyButton *mybutton = [[MyButton alloc] init];

[mybutton addTarget:self action:@selector(actionMethod)];

...

 

-(void)actionMethod{

//some code

}

Currently rated 4.2 by 5 people

  • Currently 4.2/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Icons for universal application (iPhone/iPad)

by alex 17. May 2010 12:52

//Add icnon files to projects

//Add following to info.plist

 

<key>CFBundleIconFiles</key>

<array>

<string>Icon.png</string>

<string>iconiPad.png</string>

</array>

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Hide back button

by alex 18. March 2010 13:40

[self.navigationItem setHidesBackButton:YES];

Currently rated 3.5 by 4 people

  • Currently 3.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Convert image to/from text (Base64)

by alex 14. March 2010 15:56

#import "NSDataAdditions.h"

 
 
 

-(NSString *)getStringFromImage:(UIImage *)image{

if(image){

NSData *dataObj = UIImagePNGRepresentation(image);

return [dataObj base64Encoding];

} else {

return @"";

}

}
 
//Convert back 

NSData *dataObj = [NSData dataWithBase64EncodedString:beforeStringImage];

UIImage *beforeImage = [UIImage imageWithData:dataObj];

 

NSDataAdditions.zip (2.80 kb)

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Check if camera is available

by alex 28. February 2010 12:34

if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){

cameraButton.enabled = NO;

} else {

cameraButton.enabled = YES;

}

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Show file included into project in UIWebView

by alex 22. February 2010 16:33

NSString *path = [NSString stringWithString:[[NSBundle mainBundle] pathForResource:@"feedback" ofType:@"html"]];

webView.opaque = NO;

webView.backgroundColor = [UIColor clearColor];

[webView setDelegate:self];

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path isDirectory:NO]]];


Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Get MD5 hash from NSData

by alex 16. February 2010 10:57

#import "NSData+md5.h"

#import <CommonCrypto/CommonDigest.h>

 

 

@implementation NSData (Md5)

 

-(NSString*)md5{

const char *cStr = [self bytes];

unsigned char digest[CC_MD5_DIGEST_LENGTH];

CC_MD5( cStr, [self length], digest );

NSString* s = [NSString stringWithFormat: @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",

  digest[0], digest[1], 

  digest[2], digest[3],

  digest[4], digest[5],

  digest[6], digest[7],

  digest[8], digest[9],

  digest[10], digest[11],

  digest[12], digest[13],

  digest[14], digest[15]];

return s;

}


 

@end

Currently rated 3.7 by 3 people

  • Currently 3.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Get Coordinates from Address

by alex 15. February 2010 15:47

 

-(CLLocationCoordinate2D) addressLocation:(NSString *)input {

    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv"

  [input stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

    NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];

    NSArray *listItems = [locationString componentsSeparatedByString:@","];

    double latitude = 0.0;

    double longitude = 0.0;

    if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {

        latitude = [[listItems objectAtIndex:2] doubleValue];

        longitude = [[listItems objectAtIndex:3] doubleValue];

    }

    else {

//Show error

    }

    CLLocationCoordinate2D location;

    location.latitude = latitude;

    location.longitude = longitude;

    return location;

}

 

Currently rated 4.4 by 7 people

  • Currently 4.428571/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Connect to Evernote

by alex 14. February 2010 14:02

#import "THTTPClient.h"

#import "TBinaryProtocol.h"

#import "UserStore.h"

#import "NoteStore.h"

 

 

- (void)Test

{

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

// Keep this key private

NSString *consumerKey = [[[NSString alloc]

  initWithString: @"YOUR_CONSUMER_KEY_HERE" ] autorelease];

NSString *consumerSecret = [[[NSString alloc]

initWithString: @"YOUR_CONSUMER_SECRET_HERE"] autorelease];

// For testing we use the sandbox server.

NSURL *userStoreUri = [[[NSURL alloc]

initWithString: @"https://sandbox.evernote.com/edam/user"] autorelease];

NSString *noteStoreUriBase = [[[NSString alloc]

  initWithString: @"http://sandbox.evernote.com/edam/note/"] autorelease];

// These are for test purposes. At some point the user will provide his/her own.

NSString *username = [[[NSString alloc]

  initWithString: @"YOUR_USERNAME_HERE"] autorelease];

NSString *password = [[[NSString alloc]

  initWithString: @"YOUR_PASSWORD_HERE"] autorelease];

THTTPClient *userStoreHttpClient = [[[THTTPClient alloc]

initWithURL:userStoreUri] autorelease];

TBinaryProtocol *userStoreProtocol = [[[TBinaryProtocol alloc]

  initWithTransport:userStoreHttpClient] autorelease];

EDAMUserStoreClient *userStore = [[[EDAMUserStoreClient alloc]

  initWithProtocol:userStoreProtocol] autorelease];

EDAMNotebook* defaultNotebook = NULL;

BOOL versionOk = [userStore checkVersion:@"Cocoa EDAMTest" :

  [EDAMUserStoreConstants EDAM_VERSION_MAJOR] :

  [EDAMUserStoreConstants EDAM_VERSION_MINOR]];

if (versionOk == YES)

{

EDAMAuthenticationResult* authResult =

[userStore authenticate:username :password

  :consumerKey :consumerSecret];

EDAMUser *user = [authResult user];

NSString *authToken = [authResult authenticationToken];

NSLog(@"Authentication was successful for: %@", [user username]);

NSLog(@"Authentication token: %@", authToken);

NSURL *noteStoreUri =  [[[NSURL alloc]

initWithString:[NSString stringWithFormat:@"%@%@",

noteStoreUriBase, [user shardId]] ]autorelease];

THTTPClient *noteStoreHttpClient = [[[THTTPClient alloc]

initWithURL:noteStoreUri] autorelease];

TBinaryProtocol *noteStoreProtocol = [[[TBinaryProtocol alloc]

  initWithTransport:noteStoreHttpClient] autorelease];

EDAMNoteStoreClient *noteStore = [[[EDAMNoteStoreClient alloc]

  initWithProtocol:noteStoreProtocol] autorelease];

NSArray *notebooks = [[noteStore listNotebooks:authToken] autorelease];

NSLog(@"Found %d notebooks", [notebooks count]);

for (int i = 0; i < [notebooks count]; i++)

{

EDAMNotebook* notebook = (EDAMNotebook*)[notebooks objectAtIndex:i];

if ([notebook defaultNotebook] == YES)

{

defaultNotebook = notebook;

}

NSLog(@" * %@", [notebook name]);

}

NSLog(@"Creating a new note in default notebook: %@", [defaultNotebook name]);

// Skipping the image resource section...

EDAMNote *note = [[[EDAMNote alloc] init] autorelease];

[note setNotebookGuid:[defaultNotebook guid]];

[note setTitle:@"Test note from Cocoa Test."];

NSMutableString* contentString = [[[NSMutableString alloc] init] autorelease];

[contentString setString: @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"];

[contentString appendString:@"<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml.dtd\">"];

[contentString appendString:@" <en-note>Here is the Olive Tree Test note.<br/>"];

[contentString appendString:@" </en-note>"];

[note setContent:contentString];

[note setCreated:(long long)[[NSDate date] timeIntervalSince1970] * 1000];

EDAMNote *createdNote = [noteStore createNote:authToken :note];

if (createdNote != NULL)

{

NSLog(@"Created note: %@", [createdNote title]);

}

}

[pool drain];

}


Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Check if NSDate is today

by alex 13. February 2010 16:45

NSDate *today = [NSDate date];

NSCalendar *gregorian = [[NSCalendar alloc]

 initWithCalendarIdentifier:NSGregorianCalendar];

 

NSDateComponents *weekdayComponents = [gregorian components:(NSDayCalendarUnit | NSMonthCalendarUnit |NSYearCalendarUnitfromDate:today];

NSInteger todayDay = [weekdayComponents day];

NSInteger todayMonth = [weekdayComponents month];

NSInteger todayYear = [weekdayComponents year];

 

BOOL res = NO;

 

//check if datedump is today

weekdayComponents = [gregorian components:(NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit)fromDate:dateDump];

NSInteger cday = [weekdayComponents day];

NSInteger month = [weekdayComponents month];

NSInteger year = [weekdayComponents year];

 

if (cday == todayDay &&

month == todayMonth &&

year == todayYear){

res = YES;

}


Currently rated 4.5 by 2 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen