Coming Soon: Trip Expenses

At the end of this week we will submit to Apple our new app: Trip Expenses !

Trip Expenses is an iPhone app to register your expenses while on a trip. Using Trip Expenses you will keep your expense history organized by categories with the information that you need.

For more information: http://gazapps.com/tripexpenses/

How to create a bootable, backup Mountain Lion install disk

  1. Purchase and download Mountain Lion from the Mac App Store.
  2. Right click on “OS X Mountain Lion” installer and choose the option to “Show Package Contents.”
  3. Inside the Contents folder that appears you will find a SharedSupport folder and inside the SharedSupport folder you will find the “InstallESD.dmg.” This is the Mountain Lion boot disc image we have all been waiting for.
  4. Copy “InstallESD.dmg” to another folder like the Desktop.
  5. Launch Disk Utility and click the burn button.
  6. Select the copied “InstallESD.dmg” as the image to burn, insert a standard sized 4.7 GB DVD, and wait for your new Lion Boot Disc to come out.

NSDate without time portion

The Problem

Sometimes you need to make comparation with dates, but NSDate is not actually a Date like YYYYMMDD. In fact NSDate conceptually store time relative to Jan 1, 2001, GMT. So if you get a [NSDate date] and two seconds after you get another [NSDate date] you will have two different dates.

The Solution, well… One solution of many

One way to solve this problem is to set the time portion of NSDate to a arbitrary value like 00:00:00. To do this take a look in the code that follows:

+(NSDate *) normalizedDate {
 NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
 // [gregorian setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
 [gregorian setTimeZone:[NSTimeZone localTimeZone]];

NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit | kCFCalendarUnitWeekday | kCFCalendarUnitWeekdayOrdinal fromDate:[NSDate date]];

NSDateComponents *normalized = NSDateComponents.alloc.init;
 [normalized setWeekday: [components weekday]];
 [normalized setWeekdayOrdinal:[components weekdayOrdinal]];
 [normalized setMonth:[components month]];
 [normalized setYear:[components year]];

return [gregorian dateFromComponents:normalized];
 }

In some situations you will want to set a specific time zone, to do so I suggest you to put time zone at “GMT” as the comented part of the code above.

OS X v10.8 Mountain Lion – New Frameworks

New Frameworks

The following frameworks have been added in OS X v10.8:

  • Accounts (Accounts.framework). The Accounts framework provides a single sign-on model for supported account types. Single sign-on improves the user experience because apps no longer need to prompt a user separately for login information related to an account. It also simplifies the development model for you by managing the account authorization process for your app. You can use this framework in conjunction with the Twitter framework to access a user’s Twitter account.
  • Event Kit (EventKit.framework). The Event Kit framework provides an interface for accessing a user’s calendar events and reminder items. You can use the APIs in this framework to get existing events and add new events to the user’s calendar. Calendar events can include alarms that you can configure with rules for when they should be delivered.

Note: The Calendar Store framework (CalendarStore.framework) is deprecated in OS X v10.8. You should use the programming interfaces of the Event Kit framework instead.

You can also use Event Kit APIs to access the user’s reminders, create new reminders, add an alarm to a reminder, and mark a reminder as complete.

  • Game Kit (GameKit.framework). As described in “Game Center,” the Game Kit framework provides APIs that allow your app to participate in Game Center. You can use Game Kit APIs to display leaderboards in your game, and to give users the opportunity to share their in-game achievements and play multiplayer games. To learn more about using Game Kit APIs in your app, see Game Kit Framework Reference.
  • GLKit (GLKit.framework). The GLKit framework provides libraries of commonly needed functions and classes that can help reduce the effort required to create an OpenGL app. In addition, the GLKit framework provides APIs that help you perform several optimized mathematical operations, reduce the effort in loading texture data, and render using provided effects.To learn more about using GLKit APIs in your app, see GLKit Framework Reference.
  • Twitter (Twitter.framework). The Twitter framework allows you to interact with the Twitter service. For example, using a configured Twitter account, you can send status updates (that is, “tweets”) on behalf of the user, which can also include location information and media attachments. Additionally, this framework provides classes for interacting with the Twitter developer API.
  • Video Toolbox (VideoToolbox.framework). Video Toolbox is the 64-bit replacement for the QuickTime Image Compression Manager. The Video Toolbox framework provides services for video compression and decompression, and for conversion between raster image formats stored in Core Video pixel buffers.

Drag and Drop text file on MacOS X application

Looking for this answer on the internet, I didn’t find a compiled solution for this issue. So I decided to make a simple tutorial how to build an app that act as a drag destination of a text file.

How does it works?

MacOS has a sofisticated drag-and-drop operation’s to use in your application or between applications. Using this capabilities your application could act as a Dragging Source, a Drag Destination or both.

Create our solution

1) create a new project “Cocoa Application” in Xcode named DragTest.

2) create a new file “objective-c class” named DragDropView.

To implement the drag-and-drop behavior you will need this methods:

- (NSDragOperation)draggingEntered:(id)sender

(Invoked when the dragged image enters destination bounds or frame)

- (BOOL)prepareForDragOperation:(id)sender

(Invoked when the image is released)

- (BOOL)performDragOperation:(id < NSDraggingInfo >)sender

(Invoked after the released image has been removed from the screen)

- (void)concludeDragOperation:(id)sender

(Invoked when the dragging operation is complete)

Here the implementation:

#import "DragDropView.h"

@implementation DragDropView

- (id)initWithFrame:(NSRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
    }
    return self;
}

- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender{
    highlight=YES;
    [self setNeedsDisplay: YES];
	return NSDragOperationGeneric;
}

- (void)draggingExited:(id <NSDraggingInfo>)sender{
    highlight=NO;
    [self setNeedsDisplay: YES];
}

- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender {
    highlight=NO;
    [self setNeedsDisplay: YES];
    return YES;
}

- (BOOL)performDragOperation:(id < NSDraggingInfo >)sender {
    NSArray *draggedFilenames = [[sender draggingPasteboard] propertyListForType:NSFilenamesPboardType];
    if ([[[draggedFilenames objectAtIndex:0] pathExtension] isEqual:@"txt"]){
        return YES;
    } else {
        return NO;
    }
}

- (void)concludeDragOperation:(id <NSDraggingInfo>)sender{
    NSArray *draggedFilenames = [[sender draggingPasteboard] propertyListForType:NSFilenamesPboardType];
    NSString *textDataFile = [NSString stringWithContentsOfFile:[draggedFilenames objectAtIndex:0] encoding:NSUTF8StringEncoding error:nil];

    NSLog(@"%@", textDataFile);
}

- (void)drawRect:(NSRect)rect{
    [super drawRect:rect];
    if ( highlight ) {
        [[NSColor grayColor] set];
        [NSBezierPath setDefaultLineWidth: 5];
        [NSBezierPath strokeRect: [self bounds]];
    }
}

@end

3) Now, select the MainMenu.xib.

4) Drop one CustomView into the Window.

5) in the “identity inspector” tab, in the “custom class” comboBox select the DragDropView.

it’s done !

How to install Java for Mac OS X 10.7 Lion

  • Go to Applications -> Utilities -> Java Preferences, and open it
  • Make sure you are connected to Internet. Simply click install, and after accepting the license agreement, your Java runtime will be downloaded and installed.

RoadMap to install or update to OSX 10.7 Lion

lion.175x175-75

 

To help everyone who wants to install Lion I decided to create a RoadMap:

1) Verify if your hardware is compatible. In order to install Mac OS X 10.7 you will need:
  • Intel Core 2 Duo, Core i3, Core i5, Core i7, or Xeon processor
  • 2GB of RAM
  • Mac OS X 10.6.6 or later with the Mac App Store installed
  • At least 4GB of additional disk space to accommodate the download, but more is obviously recommended
2) Verify if all apps you need are Lion compatible. You can see about apps compatibility at:

http://roaringapps.com/

3) Backup all your data. The best way to do that is buy an external HD and use Time Machine. To do that take a look at this article:

http://support.apple.com/kb/ht1427

3) Purchase and download Lion from the Mac App Store on any Lion compatible Mac running Snow Leopard:

http://itunes.apple.com/us/app/os-x-lion/id444303913?mt=12

4) Make a USB drive or DVD image of the Lion’s installation
  • Right click on “Mac OS X Lion” installer and choose the option to “Show Package Contents.”
  • Inside the Contents folder that appears you will find a SharedSupport folder and inside the SharedSupport folder you will find the “InstallESD.dmg.” This is the Lion boot disc image we have all been waiting for.
  • Copy “InstallESD.dmg” to another folder like the Desktop.
  • Launch Disk Utility and click the burn button.
  • Select the copied “InstallESD.dmg” as the image to burn, insert a standard sized 4.7 GB DVD, and wait for your new Lion Boot Disc to come out toasty hot.
5) Run the installation

Basic ShareKit customization

ShareKit is an open source framework for iOS apps to add capabilities to share information with many internet services.

Your app can share information with this supported services: Delicious, Email, Facebook, Google Reader, Instapaper, Pinboard, Read It Later, Tumblr, Twitter.

ShareKit has your own interface to connect with the services, but you can customize Sharekit to connect those services in your own way. Let get start our step-by-step tutorial.

1) Create your project.

a. Enter in xcode and create a new project with “view-based application” template;
b. Name the project as “SharekitTest”;
c. Place a UIButton in the SharekiTestViewController.xib;

d. Control-drag the UIButton to the location in the SharekiTestViewController.h you want. When you release the mouse button, Xcode displays a small dialog. Set the connection field to “Action” and the name field to “facebookButtonTapped”

e. Save your project.

2) Add Sharekit to your app

a. Take a look at http://getsharekit.com/install
b. Follow steps 1 and 2 and get back to this tutorial

3) Register your app to developer’s service site.

a. Register your app to http://www.facebook.com/developers, login with your account;
b. Fill the form with your app’s information;
c. You should have consumer key and consumer secret now.

4) Locate and open the file SHKConfig.h an fill the key and secret.
// Facebook - http://www.facebook.com/developers
// If SHKFacebookUseSessionProxy is enabled then SHKFacebookSecret is ignored and should be left blank

#define SHKFacebookUseSessionProxy  NO
#define SHKFacebookKey				@"248989898989898849"
#define SHKFacebookSecret			@"7a6242232323232323236b4997138b1c"
#define SHKFacebookSessionProxyURL  @""
5) Import the headers in the SharekiTestViewController.h
#import "SHK.h"
#import "SHKFacebook.h"
6) Insert the code below in the “FacebookButtonTapped” method in SharekiTestViewController.m to share what you want.
- (IBAction)FacebookButtonTapped:(id)sender {
    SHKItem *item;
    NSURL *url = [NSURL URLWithString:@""http://www.gazapps.com""];
    item = [SHKItem URL:url title:@"Checkout this site"];
    [SHKFacebook shareItem:item];
}

In this code we create an SHKItem. It has four methods, one for each information you want to share: URL, Images, Text and Files. Then we create an url, set the url to the SHKItem and finally set the item to shareItem method to be published.

It’s done ! You can do a lot more customizations, go to the sharekit website and have fun!

Add and delete customized UITableViewCell

Apple AppStore is a huge success. There is more than 400 thousands apps’s. So if you want to be noted is better you create a very interesting app. To do that in most cases you will want to customize the UI of your app. One very powerfull customization is change the tableview. You can do a lot of stuff changing the tableviewcell and probably you will want to put another UI elements inside the cell. In that case we may have a tricky situation when you have to add and remove customized cells from one tableview.

Animate the deletion from tableView

Apple provide an animated way to remove cells from tableView. You only have to remove the item you want from the collection that store tableview’s data (a NSMutableArray, for example) and then call deleteRowsAtIndexPaths method from tableview as follows:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self.tableViewData count]>1) {
        // If row is deleted, remove it from the list.
        if (editingStyle == UITableViewCellEditingStyleDelete)
        {
            [self.tableView beginUpdates];
            [self.tableViewData removeObjectAtIndex:indexPath.row];

            // Animate the deletion from the table.
            [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
            [self.tableView endUpdates];
        }
    }
}

Modifying layer that is being finalized

Imagine you have tableviews with cells that has textfields. And imagine you want to add and remove cells from this tableview. In that case you may have a problem with the cell deletion procedure. If you add and delete cells a few times probably you will receive this error message from the compiler:

GNU gdb 6.3.50-20050815 (Apple version gdb-1518) (Sat Feb 12 02:52:12 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 663.
2011-07-10 20:35:27.117 iScoreKeeper[663:207] modifying layer that is being finalized - 0x4e40450
Current language:  auto; currently objective-c

Why is it occur?

The tableView cell’s content are referred in two collections – into the collection that store tableview’s data and in the tableview itself. So, when you delete one cell the animated deletion procedure is executed in two steps: first it removes the object from the tableview model and second removes the cell from tableview.

In the case of our example, we have a NSMutableArray with textfields as cell’s content. When you remove the object (textfield) from the NSMutableArray it will receive a release message. So this tableviewcell will lost the reference of the textfield causing the crash.

The solution

Actually the solution is very simple. You only have to retain an reference of the object before you remove it from the NSMutableArray, then tableview will be able to do its job. See as follows:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self.tableViewData count]>1) {
        // If row is deleted, remove it from the list.
        if (editingStyle == UITableViewCellEditingStyleDelete)
        {
            [self.tableView beginUpdates];
            // delete your data item here
            UITextField *tf = [self.tableViewData objectAtIndex:indexPath.row];
            [tf retain];
            [tf removeFromSuperview];
            [self.tableViewData removeObjectAtIndex:indexPath.row];

            // Animate the deletion from the table.
            [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
            [self.tableView endUpdates];
        }
    }
}

I hope it helps !

6 steps to build an iphone app




Premium Wordpress Plugin