List of all Iphone and Blackberry Development codes in a one click Iphone,objective C,xcode,blackberry Development,iOS Development

Saturday, November 15, 2014

Database operations on IOS

Create table-

NSString *docsDir;
    NSArray *dirPaths;
   
    dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    docsDir = dirPaths[0];
databasePath = [[NSString alloc]initWithString:[docsDir stringByAppendingPathComponent:@"contacts.db"]];
 NSLog(@"aaa: %@",databasePath);
    NSFileManager *filemgr = [NSFileManager defaultManager];

       
    if ([filemgr fileExistsAtPath:databasePath] == NO)
    {
        const char *dbpath = [databasePath UTF8String];
      
        if (sqlite3_open(dbpath, &sql) == SQLITE_OK)
        {
            char *errMsg;
            const char *sql_stmt ="CREATE TABLE IF NOT EXISTS CONTACTS (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, ADDRESS TEXT, PHONE TEXT)";
           
            if (sqlite3_exec(sql, sql_stmt, NULL, NULL, &errMsg) != SQLITE_OK)
            {
                NSLog(@"Failed to create table");
            }
            sqlite3_close(sql);
        }
        else
        {
            NSLog(@"Failed to open/create database");
        }
    }


Save data-

    sqlite3_stmt    *statement;
    const char *dbpath = [databasePath UTF8String];
   
    if (sqlite3_open(dbpath, &sql) == SQLITE_OK)
    {
       
        NSString *insertSQL = [NSString stringWithFormat:@"INSERT INTO CONTACTS (name, address, phone) VALUES (\"%@\", \"%@\", \"%@\")",tx1.text, tx2.text, tx3.text];
       
        const char *insert_stmt = [insertSQL UTF8String];
        sqlite3_prepare_v2(sql, insert_stmt,
                           -1, &statement, NULL);
        if (sqlite3_step(statement) == SQLITE_DONE)
        {
            NSLog(@"Contact added");
        
        }
        else
        {
            NSLog(@"Failed to add contact");
        }
        sqlite3_finalize(statement);
        sqlite3_close(sql);
    }



Search values -

  const char *dbpath = [databasePath UTF8String];
    sqlite3_stmt    *statement;
  

    if (sqlite3_open(dbpath, &sql) == SQLITE_OK)
    {
        NSString *querySQL = [NSString stringWithFormat:
                              @"SELECT address, phone FROM contacts WHERE name=\"%@\"",
                              tx1.text];
       
        const char *query_stmt = [querySQL UTF8String];
       
        if (sqlite3_prepare_v2(sql,query_stmt, -1, &statement, NULL) == SQLITE_OK)
        {
            if (sqlite3_step(statement) == SQLITE_ROW)
            {
                           
                NSString *addressField = [[NSString alloc]
                                          initWithUTF8String:
                                          (const char *) sqlite3_column_text(statement, 0)];

             
                NSString *phoneField = [[NSString alloc]
                                        initWithUTF8String:(const char *)
                                        sqlite3_column_text(statement, 1)];
                tx2.text = addressField;
                tx3.text = phoneField;
              
            }
            else
            {
                NSLog(@"No data Found");
            
            }
            sqlite3_finalize(statement);
        }
        sqlite3_close(sql);
    }

Xcode 6 Creating Xib From StoryBoard

The first step is to remove Main.storyboard, LaunchScreen.xib, ViewController.h, and ViewController.m—select them all, right-click, and choose to either remove them from the project, or delete them completely:
If you run the app at this point, you’ll get an exception: “Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘Could not find a storyboard named ‘Main’ in bundle…” This is because the project is trying to use that storyboard file you just removed. This information is in the project’s Info.plist, and the entry is “Main storyboard file base name”:To fix this, simply remove the entry (select it and hit delete or hover and click the remove icon).
Open AppDelegate.m, and edit applicationDidFinishLaunchingWithOptions so that it looks like this:
 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

In order to get to the functional equivalent of an Xcode 4 Single View Application, we need to add a View Controller and its corresponding xib file, and hook them up. The first step is to add a subclass of UIViewController and a corresponding xib file. Use ⌘-N or the File->New->File.. menu item to create a new file, and select “Cocoa Touch Class”: The next dialog asks you to name the class; I cleverly called mine “ViewController”. Make it a subclass of “UIViewController”, and check the “Also create XIB File”:
This will create three files in your project: ViewController.h, ViewController.m, and ViewController.xib:

Running the app at this point will give you the same behavior as before, as we’ve not yet told your app to actually use the ViewController. To do this, we need to add a property to the AppDelegate, to hold the ViewController; edit AppDelegate.h so it looks like this:
#import
 
@class ViewController;
 
@interface AppDelegate : UIResponder <UIApplicationDelegate>
 
@property (strong, nonatomic) UIWindow *window;
 
@property (strong, nonatomic) ViewController *viewController;
 
@end
 
and then edit didFinishLaunchingWithOptions  so it looks like this:
 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

Friday, September 20, 2013

Splash / Loading Screen in Blackberry

The following code will display splash screen.
public class App extends UiApplication {
     public static App theApp;
   
     public static void main(String[] args) {
       
                 theApp = new App();
                 theApp.enterEventDispatcher();   
           
           
        }  
   
    public App() {
          
            splash next = null;
            splash1 splash1=new splash1(this ,next);
            pushScreen(splash1);
           

    }
}

splash1 class is given below-
    public splash1(UiApplication app, splash next){
        application=app;
        VerticalFieldManager vfm=new VerticalFieldManager();
        final Bitmap header_Bitmap =Bitmap.getBitmapResource("splash.png");
        BitmapField bit =new BitmapField(header_Bitmap);
        vfm.add(bit);
        add(vfm);
      
         timer = new Timer();
         timer.schedule(new CountDown(), 1000);
             
    }

     public class CountDown extends TimerTask {
          public void run() {
             DismissThread dThread = new DismissThread();
             application.invokeLater(dThread);
          }
       }
     public void dismiss() {
          timer.cancel();
          application.popScreen(this);
       
          application.pushScreen(next);
       }
       public class DismissThread implements Runnable {
              public void run() {
                 dismiss();
              }
           }
}

splash class is the landing page(Home page)-
public class splash extends MainScreen {
        public splash(){
    //Here you can add your fields.......
  }
}

Thursday, September 5, 2013

Creating Facebook Like Slider Menu in Blackberry

 For creating a sliding bar like android facebook app, refer the following code. You have to customize it. Its only give you the idea. you have to implement it in your own way.




public final class MyScreen extends MainScreen
{
    boolean val=false;
    VerticalFieldManager vfm_r1;

    public MyScreen()
    {       

        final ButtonField l=new ButtonField("menu");
       
       
        final HorizontalFieldManager hfm_main=new HorizontalFieldManager();
       
        final VerticalFieldManager vfm_l=new VerticalFieldManager(){
             protected void sublayout(int maxWidth, int maxHeight) {
                    super.sublayout(280, maxHeight);
                    setExtent(280, maxHeight);
                }
             protected void paint(Graphics g){
                    g.setBackgroundColor(Color.RED);
                    // Clears the entire graphic area to the current background
                    g.clear();
                    super.paint(g);
                }
        };
        final VerticalFieldManager vfm_r=new VerticalFieldManager(){
             protected void sublayout(int maxWidth, int maxHeight) {
                 super.sublayout(maxWidth+300, maxHeight);
                 setExtent(maxWidth, maxHeight);
             }
             protected void paint(Graphics g){
                 g.setBackgroundColor(Color.YELLOW);
                 // Clears the entire graphic area to the current background
                 g.clear();
                 super.paint(g);
             }
        };
       
        vfm_l.add(new LabelField("sliding pannel"));
        
        vfm_r.add(l);
        vfm_r.add(new LabelField("main view"));
       
        hfm_main.add(vfm_r);
       
        add(hfm_main);
       
     FieldChangeListener listener=new FieldChangeListener() {
           
            public void fieldChanged(Field field, int context) {
                if(field==l){
                    if(!val){
                        val=true;
                        hfm_main.deleteAll();
                        hfm_main.add(vfm_l);
                        hfm_main.add(vfm_r);
                        hfm_main.invalidate();
                       
                }else{
                    val=false;
                    hfm_main.deleteAll();
                    hfm_main.add(vfm_r);
                    hfm_main.invalidate();
                                       
                }
                }
            }
        };
        l.setChangeListener(listener);
       
    }
}