Remove duplicates from NSArray

by alex 10. April 2012 20:26

NSArray *arrWithDuplicates = [[NSArray alloc] initWithObjects: @"Bob", @"Bob",@"Olga", @"Olga", @"Robin", nil];

NSArray *cleanedArray = [[NSSet setWithArray:arrWithDuplicates] allObjects];

NSLog(@"%@", [cleanedArray description] );    


Tags:

Add days to NSDate

by alex 10. April 2012 03:12

 

for (int i = 1; i < 30; i++) {

    NSDate *newDate = [startDay.date dateByAddingTimeInterval:60*60*24*i];

    MDay *day = [[MDay alloc] init];

    day.date = newDate;

    [list addObject:day];

}

 

Tags:

Handle taps within a UIWebView

by alex 2. January 2012 08:57

//1. Add UIGestureRecognizerDelegate to your interface:

 

@interface DocumentViewControler : UIViewController <UIGestureRecognizerDelegate>

 

//2. Add to viewDidLoad

 

- (void)viewDidLoad {

    [super viewDidLoad];

    

    

    UITapGestureRecognizer* singleTap=[[UITapGestureRecognizer

                                        alloc]initWithTarget:self action:@selector(handleSingleTap:)];

    singleTap.numberOfTouchesRequired=1;

    singleTap.delegate=self;

    [self.webView addGestureRecognizer:singleTap];

    [singleTap release];

}

 

//3. Add:

 

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer

shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer

                                                    *)otherGestureRecognizer {

    return YES;

}

 

//4.

 

-(void) handleSingleTap:(UITapGestureRecognizer *)recognizer  {

    NSLog(@"handleSingleTap");

    

    // Your code here

}

@end

Check if file exists

by alex 4. July 2011 18:46

BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:imagePath];

Show UIActionSheet

by alex 14. March 2011 01:45

 

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

//SMS

if(buttonIndex == 0){


}

//EMAIL

if (buttonIndex == 1){

 

 

}

else

{

}

}

 

-(IBAction)emailAction{

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Send by" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"SMS", @"Email",nil];

actionSheet.actionSheetStyle = UIActionSheetStyleDefault;

[actionSheet showInView:self.view];

[actionSheet release];

}


UIAlertView without Buttons

by alex 12. March 2011 08:17

//Declare in class following vairiable

UIAlertView *alert;

 

-(void)showAlert{

    alert = [[[UIAlertView alloc] initWithTitle:@"Please Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];

    

    [alert show];

 

    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

 

    indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);

    [indicator startAnimating];

    [alert addSubview:indicator];

    [indicator release];

}

 

-(void)dismissAlert{

    [alert dismissWithClickedButtonIndex:0 animated:YES];

    [alert release];

}


Send SMS

by alex 11. March 2011 00:09

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{

switch (result) {

case MessageComposeResultCancelled:

NSLog(@"Cancelled");

break;

case MessageComposeResultFailed:{

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Application" message:@"Unknown Error"

  delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];

[alert show];

[alert release];

break;}

case MessageComposeResultSent:

break;

default:

break;

}

[self dismissModalViewControllerAnimated:YES];

}

 

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

//SMS

if(buttonIndex == 0){

MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];

if([MFMessageComposeViewController canSendText])

{

controller.body = @"SMS Body";

controller.messageComposeDelegate = self;

controller.delegate = self;

[self presentModalViewController:controller animated:YES];

} else {

}

}

}

Tags:

Surviving BlackBerry

by alex 9. March 2011 21:48

Hello,

Recently I was asked to port application from iPhone/Android to Blackberry.

 Check out my separate blog about this "adventure" 

Thanks,

Alexander 

Tags:

Get current app version number from AndroidManifest.xml

by alex 20. February 2011 05:26

  //Usage from activity:

  //String verison = GlobalSettings.getVersionName(this,MyActivity.class)

  public static String getVersionName(Context context, Class cls) {

    try {

      ComponentName comp = new ComponentName(context, cls);

      PackageInfo pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0);

      return "Version: " + pinfo.versionName;

    } catch (android.content.pm.PackageManager.NameNotFoundException e) {

      return null;

    }

  }


Tags:

Get current app version number from bundle

by alex 6. December 2010 00:02

[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen