Posted tagged ‘iPhone’

Using a Pre-Populated SQLite Database with Core Data on iPhone OS 3.0

July 13, 2009

I was recently re-writing a yet to be published iPhone app to use Core Data with a pre-populated SQLite database. I was able to get the app to function with a new database using the CoreDataBooks sample code as a reference but could not get the app to read a pre-populated database added to the project.

After many hours of troubleshooting, I discovered differences in the pre-populated database and a Core Data created SQLite database. The pre-populated database consisted of just my simple 1 table structure and the Core Data created SQLite database consisted of “extra ‘Z’ tables’ For example: Z_METADATA, I searched the Internet and Apple docs but could not find a utility or any other way to convert or prep a pre-populated SQLite database for use with Core Data.

Right or wrong. Here’s what I finally did (NOTE: All the ‘coding’ is based on the CoreDataBooks sampe):

In XCode:

1. Ensure the CoreData framework is added to your project.

image

** If creating a new project, check the ‘Use Core Data for storage’ option when selecting a template.

image

2. Create the Data Model file (xcdatamodel) if not already created.

a. Click File | New File.

b. Choose iPhone OS | Resource | Data Model

image

c. Click Next, name the file and click Next again.

d. If the model class is already created, select it from   the  next window. You can create it later if it isn’t created already.

image

2. Add an Entity (table name) and bind it to the class.

a. Click Design | Data Model | Add Entity

b. Rename Entity to the table name you wish to create and change the Class to the desired class name.

image

3. Create the Attributes (columns).

a. Click Design | Data Model | Add Attribute

b. Rename newAttribute to the desired column name and set the type.

image

c. Repeat step b for each additional attribute.

image

4. Set the name of the SQLite database name and location in the AppDelegate.m file (Please refer to the CoreDataBooks sample code for further info).

– (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator != nil) {
return persistentStoreCoordinator;
}
NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @”CoreData.sqlite”];
/*
Set up the store.
For the sake of illustration, provide a pre-populated default store.
*/
NSFileManager *fileManager = [NSFileManager defaultManager];
// If the expected store doesn’t exist, copy the default store.
if (![fileManager fileExistsAtPath:storePath]) {
NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@”CoreData” ofType:@”sqlite”];
if (defaultStorePath) {
[fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
}
}

NSURL *storeUrl = [NSURL fileURLWithPath:storePath];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];

NSError *error;
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
// Update to handle the error appropriately.
NSLog(@”Unresolved error %@, %@”, error, [error userInfo]);
exit(-1);  // Fail
}
return persistentStoreCoordinator;
}

5. Build and Run the app.

In Finder:

1. Use Spotlight to search for the SQLite database created by the app in the iPhone Simulator. This is /Users/<Username>/Library/Application Support/iPhone Simulator/User/Application/<Application GUID>/Documents/<database name.sqlite>

2. Copy that database to a working folder.

3. Populate that database.

4. Add the populated database to the project.

I hope this helps! If anyone has a better or preferred way of formatting a SQLite database for use with Core Data, please let me know.

Part 2: Citrix Receiver for iPhone

May 5, 2009

Here’s some screen captures of the administration piece for the Citrix Receiver for iPhone.

iPhone SettingsCitrix Settings

 

 

 

 

 

 

 

 

 

 

Account Settings:

Account Settings

 

 

 

 

 

 

 

 

 

 

Keyboard Settings (4 Screen Captures):

Keyboard Settings 1Keyboard Settings 2

 

 

 

 

 

 

 

 

 

 

Keyboard Settings 3Keyboard Settings 4

 

 

 

 

 

 

 

 

 

 

What would an app be without an About screen?

About

Citrix Receiver for iPhone

April 29, 2009

I downloaded and installed the Citrix Reciver for iPhone (aka Project Braeburn) the day after it was released and just now found the time to blog about it. I put together the following to give you an idea of what the Receiver looks like on the iPhone. It is pretty simple to download from Apple’s App Store and simple to configure. You will need to create a XenApp Services site in the Access Management Console.

citrix-access-console2

After the short download and installation, the Citrix icon will appear on your iPhone.

citrixicon1

When you start the application you will be prompted to enter your server address, username, password and domain name. There’s also an option for whether you want the app to remember your password. Once this is set the app will connect to your XenApp Services site and provide your XenApp client application folder structure.

pleasewaitfolders

 

 

 

 

 

 

 

 

 

 

For this test, we’ll select Adobe Reader.

applist1preparing1

 

 

 

 

 

 

 

 

 

 

 

adobe-running2

Pretty simple, huh? 

The following pciture shows how to use iPhone gestures with the Citrix Receiver for iPhone.

gestures

It is definately worth downloading and using. For more information, checkout the Citrix Comminity Blog.

iPhone Dev: Magnifying Glass Icon in UITableView Index

March 3, 2009

Have you ever wondered how to get the little magnifying glass icon in the UITableView Index like in the Contacts application? Well, I did.

Thanks to Ian Baird for his reply at http://stackoverflow.com/questions/235120/whats-the-uitableview-index-magnifying-glass-character for the answer!

Microsoft Tag

January 18, 2009

Get the Microsoft Tag reader software for Windows Mobile at http://www.microsoft.com/tag or checkout the AppStore to download for iPhone. Check out the text embedded in the tag below:

barcode-1

It should open the text in your Smartphone’s text editor/viewer. Also, check out this cool site for more information: http://www.istartedsomething.com/.