Powered By Blogger

Wednesday, June 13, 2012

iPhone/iOS/iPad/Apple Sample Code

 Hi everyone,
Sample code is one of the most useful tools for learning about programming. Here's a collection of links I've found so far. Does anyone know of some other sources for iPhone sample code?

    •    Apple Sample Code: http://developer.apple.com/iphone/library/navigation/SampleCode.html
    •    Apps Amuck 31 days: http://appsamuck.com/
    •    Beginning iPhone Development: http://www.iphonedevbook.com/
    •    Chris Software: http://chris-software.com/index.php/dev-center/
    •    Dave DeLong's downloads: http://www.davedelong.com/downloads
    •    Delicious.com: http://delicious.com/alblue/iphonehttp://web.me.com/smaurice/AppleCoder/iPhone%5FOpenGL/Archive.htmlhttp://iphonedevelopment.blogspot.com/2009/05/opengl-es-from-ground-up-table-of.html
    •    iPhone Developer's Cookbook: http://code.google.com/p/cookbooksamples/downloads/list
    •    iPhone SDK source code: http://sites.google.com/site/iphonesdktutorials/sourcecode
    •    Joe Hewitt three20: http://joehewitt.com/post/the-three20-project/
    •    Stanford iPhone code: http://www.stanford.edu/class/cs193p/cgi-bin/downloads.php
    •    WiredBob (TabBar in Detail view): http://www.wiredbob.com/blog/2009/4/20/iphone-tweetie-style-navigation-framework.html
    •    BYU Cocoaheads : http://cocoaheads.byu.edu/
    •    Big Nerd Ranch: http://weblog.bignerdranch.com/
    •    Cocoa with love: http://cocoawithlove.com/
    •    Will Shipley: http://wilshipley.com/blog/
    •    mobile.tuts: http://mobile.tutsplus.com/
  
                                            •    Just sample code:
  
    •    Google Code: http://code.google.com/hosting/search?q=label%3Aiphone
    •    iPhone Cool Projects: http://www.apress.com/book/view/143022357x
    •    iPhone Game Projects: http://www.apress.com/book/downloadfile/4419
    •    Learn Objective-C on the Mac: http://www.apress.com/book/downloadfile/4175
    •    iCode Blog: http://icodeblog.com/
    •    Raywenderlich Tutorials: http://www.raywenderlich.com/
    •    OpenGLS: http://iphonedevelopment.blogspot.com/2009/05/opengl-es-from-ground-up-table-of.html

Monday, June 11, 2012

How to delete records from table in iOS SDK?



Hi,
you have to add "sqlite3.dylib " and import the "sqlite3.h" file.

#import "sqlite3.h"

+(BOOL)deleteAllColors
{
    BOOL retVal = FALSE;
    sqlite3 *database = nil;
    sqlite3_stmt *stmt = nil;
    NSString *sql = nil;
   
    NSInteger op_status = sqlite3_open([[ApplicationData returnDatabasePath] UTF8String], &database);
   
    @try
    {
        if (op_status==SQLITE_OK)
        {
            sql = [NSString stringWithFormat:@"delete from Color"];
            op_status = sqlite3_prepare(database, [sql UTF8String], -1, &stmt, nil);
            if (op_status!=SQLITE_OK)
            {
                goto end_of_transaction;
            }
            op_status = sqlite3_step(stmt);
            if (op_status != SQLITE_DONE)
            {
                goto end_of_transaction;
            }
            retVal = TRUE;
        }
    end_of_transaction:
        if (stmt!=nil) {
            sqlite3_finalize(stmt);
            stmt=nil;
        }
        if (database!=nil) {
            sqlite3_close(database);
            database=nil;
        }
        sql = nil;
    }
    @catch (NSException * e)
    {
        // thhrow exception
        if (stmt!=nil) {
            sqlite3_finalize(stmt);
            stmt=nil;
        }
        if (database!=nil) {
            sqlite3_close(database);
            database=nil;
        }
        sql = nil;
    }
    return retVal;
}

How to put UIPickerView on UIActionSheet?

    Hello,
I'm going to explain you the combination of "UIPickerView" and "UIActionSheet".
Please check the below code. I hope you will definitely find it helpful.

UIActionSheet *actionSheet = [[[UIActionSheet alloc]initWithTitle:@"sasdasd" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil] autorelease];
    [actionSheet showInView:self.view];
    [actionSheet setBounds:CGRectMake(0, 0, 320, 470.0)];

    UIPickerView *pickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0.0, 44.0, 320.0, 250.0)];
    pickerView.delegate = self;
    pickerView.dataSource = self;
    pickerView.showsSelectionIndicator = YES;
   
    UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    pickerToolbar.barStyle = UIBarStyleBlack;
    [pickerToolbar sizeToFit];
   
    NSMutableArray *barItems = [[NSMutableArray alloc] init];
   
    UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    [barItems addObject:flexSpace];
   
    UIBarButtonItem *btnBarCancel = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(btnBarCancelClicked:)];
    [barItems addObject:btnBarCancel];
   
    [pickerToolbar setItems:barItems animated:YES];
   
    [actionSheet addSubview:pickerToolbar];
    [actionSheet addSubview:pickerView];

    [flexSpace release];
    flexSpace = nil;
   
    [btnBarCancel release];
    btnBarCancel = nil;
   
    [barItems release];
    barItems = nil;

    [pickerToolbar release];
    pickerToolbar = nil;
   
    [pickerView release];
    pickerView = nil;

    [actionSheet release];

If any one has query then place you it over here.

Thanks and Regards,
Nilesh Prajapati
 

How to check network reachability?

Hi everyone,
 Here, I 'm going to share reachability code for iOS SDK. By placing this content you can check network reachability before doing any internet task in your application.

For this you have to add "SystemConfiguration.framework"  into your project.

#import <sys/socket.h>
#import <netinet/in.h>
#import <SystemConfiguration/SystemConfiguration.h>


+(BOOL)ConnectedToInternet
{
    struct sockaddr_in zeroAddress;
    bzero(&zeroAddress, sizeof(zeroAddress));
    zeroAddress.sin_len = sizeof(zeroAddress);
    zeroAddress.sin_family = AF_INET;
   
    SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)&zeroAddress);
    if(reachability != NULL)
    {
        //NetworkStatus retVal = NotReachable;
        SCNetworkReachabilityFlags flags;
        if (SCNetworkReachabilityGetFlags(reachability, &flags))
        {
            if ((flags & kSCNetworkReachabilityFlagsReachable) == 0)
            {
                // if target host is not reachable
                return NO;
            }
           
            if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0)
            {
                // if target host is reachable and no connection is required
                //  then we'll assume (for now) that your on Wi-Fi
                return YES;
            }
           
           
            if ((((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) ||
                 (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0))
            {
                // ... and the connection is on-demand (or on-traffic) if the
                //     calling application is using the CFSocketStream or higher APIs
               
                if ((flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0)
                {
                    // ... and no [user] intervention is needed
                    return YES;
                }
            }
           
            if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN)
            {
                // ... but WWAN connections are OK if the calling application
                //     is using the CFNetwork (CFSocketStream?) APIs.
                return YES;
            }
        }
    }
   
    return NO;
}


If any one has query then place you it over here.

Thanks and Regards,
Nilesh Prajapati
 

Tuesday, June 5, 2012

How to check valid email address in iPhone SDK?

Using the below function , you can check email address format validity. Hope , this will help you.
 
+(BOOL)checkEmailAddress:(NSString *)strEmail
{
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}";  
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];  
    return [emailTest evaluateWithObject:strEmail];
}


If any one has query then place you it over here.

Thanks and Regards,
Nilesh Prajapati