SenTestingKit not loaded, Image not found

After moving from my old macbook pro (2009) to the new macbook pro (2012) on the Xcode Version (4.5.1), i tried running my app in the iphone simulator but was faced with this error.

dyld: Library not loaded: @rpath/SenTestingKit.framework/Versions/A/SenTestingKit

I am pretty sure that it was working perfectly in the old macbook pro, therefore i set out to google and see that alot of people actually hit this issue but there wasn’t any clear cut answer.

To solve this basically, expand your solution -> Frameworks -> Remove the SenTestingKit from your project. This should resolve the issue.

Note : Please remove reference not delete it.

Xcode’s Neat Feature: “SVN”

Been working with Xcode for more than a year now, I just wanted to highlight the following neat feature available in Xcode.

The ability to take snapshot and revert this back to the way it was before.

If you work with Virtual Machine, you will appreciate this function and understand how valuable it will be.

If not let me explain, take for example you made a mistake in your development deleting some really important codes away and you can’t undo. You will either find from a backup hdd or try to rewrite it again. But with snapshot you will not need to do either of the above (provide you dont lost the development due to a dead hdd).

Creating a Snapshot

Instruction to take a snapshot:

In Xcode, File -> Create Snapshot

This will save a snapshot of the current state in the Xcode’s Organizer.

Restore the Snapshot

Restore the snapshot by going to the following:

In Xcode, File -> Restore Snapshot

Managing the Snapshots

Anyone who have publish an app or work extensively will be aware of Xcode’s Organizer, but if you dont, no worries.

In Xcode, Window -> Organizer -> Select Projects (this is the third icon out of the five on the window)

On the right of the screen, you will see the project and you can delete or export the snapshot.

I am linking the official documentation from apple. Click ME

Ending…

Ending this off, if you are not the only person working on the project, I recommend you go the commercial route which is the SCM. Eg. SVN or GitHub or TFS

But if you are just like me working on weekend project, do explore this snapshot features that comes along with the XCode.

Making UILabel Clickable

Many times we normally deal with UITextField and UIButton, this 2 controls allow for user-interaction easily but have not UILabel.

But at times you will still want to use UILabel with an option to allow for user-interaction.

This show code segment allows for you to add a touch event listener to the UILabel. Continue reading “Making UILabel Clickable”

Tip of the Day for Xcode and Sqlite

This is one of the simplest but could also be the toughest to crack.

Imagine this, you wrote most of the Database class for your new application . At the same time you have created your database schema, and save a copy of the file (.sqlite) in where your project folder is.

You tried running the codes but it seems that there’s a error with the file not found.

To resolve this simply add the Application.sqlite file to your xcode project.

Then make sure that under Targets-> Build Phases -> Copy Bundle Resources,  you have your Application.sqlite in there.

To really confirm again, when you have ran your simulator once, you can browse to the following path,

/Users/<yourname>/Library/Application Support/iPhone Simulator/5.0/Applications/<GUID>/<ApplicationName>.app

Right Click on the file and show content.

Happy Coding!

Strings!!!

Anyone who have done some form of programming will know of this term, Strings!

Its one of the more commonly used in the programming environment.

Today, I am writing this to talk about performance of Strings in C#.

String strValue = “This is a String”;

Above is a simple string declaration.

Consider the following example:

String strValue = “This is a String”;
strValue += ” This is another String”;
strValue += ” This is the Third String”;

The above method in .NET will use more memory, reason being that += will create a new string and discard the previous ones to the garbage collector (this is something alot of developers in .net doesnt care about because .net deal with it).

Instead of the above, do the following:

1.
Stringbuilder builder = new Stringbuilder (“This is  a String”);
builder.append(” This is another string”);

2.
string newString = String.Format(“{0} {1}”, “This is a String”, strValue);

SQL : Maximum Recursion Limit

Recently at work, I got back in touch with dealing with Microsoft .NET technology.

Something that I haven’t working on for awhile, long story short the requirements was simple generate report to webpart (Sharepoint) using their custom application database.

Seems fairly simple, but with a fairly complex database schema, I adopted the view approach and leave all complex data manipulation to the SQL Server.

Until I hit the following error,

MAXIMUM RECUSION LIMIT 100 have been reach.

This normally means that you are not able to progress further, after much figuring with the problem. I have found 2 solutions.

1. Data Issue, in my case this was the problem, due to the quality of the  sample data. I had to generate my own data sample and it was all good.

2. You will have to add “option (maxrecusion 1000)” after your select statement.

A little bit more on this, the SQL Server maximum recursion is 32767.

By default this value is set as 100, therefore you can set the number anywhere from 0 to 32767.

Note:
To bypass this error, you can simply set this to ZERO, but this doesnt mean that the problem goes away.
The reason this error appears means that the sql query that was written have some issue and its best to find the root cause of it.

Standard Height and Size for iphone

UIView – 320x460UINavigationBar – 320×44
UITabBar – 320×49
UISearchBar – 320×44
UIToolBar – 320x44UIPickerView – 320×216
UIDatePicker – 320×216
UIKeyboard – 320x216UISegmentedControl – 320×44
UIButton xx37

UITextField – xx37
UISwitch 94×27

UIActivityIndicatorView – 37×37
UIPageControl – 38×36

UIKeyboard – Height : 170

UITableViewCell – 320×44

IOS GameKit

Implementing Bluetooth with GameKit

In this article, I will share how to enable Bluetooth with GameKit api.

First, we will have to add GameKit library to our project.
Select your project and the corresponding target.
Under “Build Phases”, expand “Link Binary with Libraries”. Click the “+” button and add the GameKit Library
When you successfully add the GameKit framework. It should appear as in Fig B.
Now that we’ve added the GameKit framework, we can move on to implementing the codes for Bluetooth connectivity.
We will now need to create a controller that will be implementing and using the Bluetooth.
In the header file, make sure you input the following codes

#import <UIKit/UIKit.h>

#import <GameKit/GameKit.h>

@interface BluetoothViewController : UIViewController<GKPeerPickerControllerDelegate,GKSessionDelegate>{

    GKSession *gkSession;

    GKPeerPickerController *gkPicker;

}

@property (nonatomicretainGKSession *gkSession;

@property (nonatomicretainGKPeerPickerController *gkPicker;

-(IBAction)connectViaBlueTooth:(id)sender;

@end

Now, we will move onto the implementation file.

@implementation ExchangeGKViewController

@synthesize gkSession, gkPicker;

- (void)viewDidLoad

{

    [super viewDidLoad];

    if (!gkSession) {

        gkSession = [[GKSession allocinitWithSessionID:nil displayName:nilsessionMode:GKSessionModePeer];

    }

    

}

With this, we will synthesize our session and picker so that we are able to use them.

We have also implemented a session to be created so that when we first load the viewcontroller, there will always be a valid session.

Now, we will create a button for the viewcontroller to look for other bluetooth peers.

Back to the header file, add in:

-(IBAction) connectViaBlueTooth:(id)sender;

-(IBAction) disconnectFromBlueTooth:(id) sender;


And implement it with :
-(IBAction)connectViaBlueTooth:(id)sender{}    gkPicker = [[GKPeerPickerController allocinit];    gkPicker.delegate = self;    gkPicker.connectionTypesMask = GKPeerPickerConnectionTypeNearby;

    [gkPicker show];

}

-(IBActiondisconnectFromBlueTooth:(id) sender {

    [self.gkSession disconnectFromAllPeers];

    gkSession.available = NO;

    [gkSession setDataReceiveHandler:nil withContext:nil];

    gkSession.delegate = nil;

    gkSession = nil;

    

}

Don’t forget to create the buttons, and link it with the corresponding IBAction.
Go ahead and test what you have so far. If everything is working well so far you will be able to see
You’ll also be able to see other devices if they are looking for bluetooth devices too.
If you’ve gotten this far. Congrats. Pretty easy so far. Now for the finishing touches.
We will need to implement codes so that the PeerPicker knows what to do when you select a peer

#pragma mark - GKPeerPickerControllerDelegate methods

- (void)peerPickerController:(GKPeerPickerController *)picker

              didConnectPeer:(NSString *)peerID

                   toSession:(GKSession *) session {

    self.gkSession = session;

    session.delegate = self;

    [session setDataReceiveHandler:self withContext:nil];

    picker.delegate = nil;

    [picker dismiss];

}

- (void)peerPickerControllerDidCancel:(GKPeerPickerController *)picker

{

    picker.delegate = nil;

}

Add in these codes so you know the changes in Bluetooth connectivity state as well as to send data and receive data.

#pragma mark - Session methods

- (void)session:(GKSession *)session

           peer:(NSString *)peerID

 didChangeState:(GKPeerConnectionState)state {

    UIAlertView *alert;

    switch (state)

    {

        case GKPeerStateConnected:{

            NSLog(@"connected");

            alert = [[UIAlertView allocinitWithTitle:@"Bluetooth connection"message:@"connected" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nilnil];

            [alert show];

        }

            break;

        case GKPeerStateDisconnected:{

            NSLog(@"disconnected");

            alert = [[UIAlertView allocinitWithTitle:@"Bluetooth connection"message:@"disconnected" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nilnil];

            [alert show];

            gkSession = nil;

        }

        case GKPeerStateAvailable:

        case GKPeerStateConnecting:

        case GKPeerStateUnavailable:

            break;

    }

}

- (void)session:(GKSession *)session didFailWithError:(NSError *)error{

    NSLog(@"Session error: %@", [error description]);

}

- (void) mySendDataToPeers: (NSData *) data

{

    [gkSession sendDataToAllPeers: data withDataModeGKSendDataReliable errornil];

}

- (void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession: (GKSession *)session context:(void *)context

{

    // Read the bytes in data and perform an application-specific action.

}


Congrats, you have now successfully implemented the bluetooth programming. Use the mySendDataToPeers to send data. And receiveData to read the data received.

Xcode : EXE_BAD_ACCESS

Struggling with EXC_BAD_ACCESS ?

This happens when you are trying to access an object that has already been released.
In order to find the root of the problem you will need to turn on Zombie objects. This prevents the releasing of memory of any objects used during run time and can help you determine the source of your troubles.
To enable Zombie objects in XCode 4.2:
  1. Press ⌥⌘R (Alt – Command – R)
  2. From the tab “Info | Arguments | Options | Diagnostics” select Diagnostics and click “Enable Zombie Objects”.

From now on, released objects will turn into zombies and will appear in the debugger stack trace

Adding Three20 to your Xcode Project

This article will cover the basic of adding the Three20 framework to your Xcode 4 solutions.

A little background of this particular framework, quoting from the source.

Three20 is a open source Objective-C library used by dozens of well-known brands in the App Store, including Facebook, Posterous, Pulse, Meetup.com, and SCVNGR. Three20 provides powerful view controllers such as the Launcher, the popular Photo Browser, and internet-aware tables.

Another post will be written to discuss about the features of the framework, Three20. But for now let’s us get started on adding this the Three20 to your Xcode 4 project.

Three20 source code could be downloaded from the following link. www.three20.info

I do strongly suggest that you download the tar.gz version.

  1. Start by extracting the content of the file you downloaded from the site.Again, I suggest that you should extract the file on the desktop.
  2. Locate the file ttmodule.py at that paticularly path three20/src/script/

    xcode4 three20 facebook
    xcode4 three20 facebook

     

  3. Open Terminal,
    Enter: python
  4. Drag ttmodule.py into the terminal window,
    Enter: -p
  5. Locate your xcode project, Drag the .xcodeproj file into the Terminal.
    Enter: Three20
  6. Check that the Terminal Window should now look something like this
    > python /Users/xxx/Desktop/three20/src/scripts/ttmodule.py -p /TestingProject/TestingProject.xcodeproj Three20
    Press Enter.

This will add the Three20 framework into the xcode project and you can find out more on how to use the following at the following site.