Archive for the ‘iPhone’ Category

18
Apr

Consider a UIButton object, myButtonObject, for which you want to give the zoom in and out animation. Now use the following code to give the desired animation to the button.

[UIView beginAnimations:nil context:myButtonObject]; // Giving the context of the animation to the button you want to animate.

[UIView setAnimationDuration:1]; // Duration of each animation in seconds

[UIView setAnimationRepeatCount:5]; // Number of times you want the animation to perform

[UIView setAnimationRepeatAutoreverses:YES]; // YES means will go back to the original state after completion of each animation loop

CGRect rect = myButtonObject.bounds; // Getting the current bounds of the button

rect.size.width += 15; // Increasing the width of the button by 15 points

rect.size.height += 15; // Increasing the height of the button by 15 points

myButtonObject.bounds = rect; // Assigning the modified width and height to the button.

[UIView commitAnimations]; // Committing the animation. Now the animation will start.

, , , ,

18
Apr

For command line installation of cocos3D, follow the following steps :

1. Set the path of the command line to the cocos3d folder.

2. Now execute the following command to install cocos3D. Please not that we are installing cocos3D as an extension of cocos2D. So you have to give like this.

./install-cocos3d.sh -u -f -2 yourcocos2dinstalledlocation

Now you are ready to go with cocos3D. If the Xcode was open when you were installing cocos3D, then restart Xcode for the changes to take effect.

, , ,

16
Apr
[mySprite runAction:[CCJumpBy actionWithDuration:0.1 position:ccp(0,0) height:10 jumps:1]];

14
Apr

Many of today’s most popular smartphones can be erased from afar if they’re misplaced or fall into the wrong hands. Here’s how to do it.

Our phones are valuable, but they’re easily replaced. The data on them, however, is often much more important. Cell phones carry all kinds of personal and business information these days, so preventing them from getting in the wrong hands is key.

All of the major smartphone platforms have some kind of remote erase capability. There are several ways of doing it, such as installing apps on the handset, using a management console on the IT side, or signing up for a cloud-based service. Here’s a rundown of what’s out there for each platform. No matter which smartphone OS you or your employees use, you’re bound to find something that can help put your mind at ease.

 
The  same features that enable the remote disable can also just be used to find the phone. Most of today’s smartphones have some form of GPS capability. That means you can use the same tools just to find or locate the lost phone in the first place—and potentially, depending on who has it, or where it’s found, get it back.

Though it varies by platform, the remote wipe solutions listed below—or any for that matter—aren’t fail-safe. If someone finds the phone before the remote wipe occurs—which could happen if the battery dies, or there’s no signal to receive the command—a thief or corporate spy could disable the network connections and then hack away. Your best insurance, therefore, is to disable the handset as quickly as possible, the same way you would call your credit card company the moment you noticed a credit card was missing.

Apple iPhone
You can now locate and remotely erase any iPhone. While you still have the device, head to Settings > iCloud and turn on Find My iPhone if it isn’t already enabled. If you lose your phone, you can find it either by installing the free ‘Find My iPhone’ app on another iOS device, or by visiting icloud.com, signing in, and using Apple’s Web-based ‘Find My iPhone’ app. With either tool, you can remotely lock the phone with a passcode if you haven’t already, send a message to it, play a sound, or remotely wipe the phone.

Google Android
‘Android Lost’ adds remote find and wipe capability, and also lets you set a password and lock the SIM card slot. You can even sound an alarm when the phone is on silent—perfect for finding it when it’s buried in the couch cushions. We’re particularly fond of Android Lost because you can push the app to the phone from Google Play (formerly the Android Market) remotely. In a corporate setting, IT managers deploying Android devices can enable native remote wipe capability by installing ‘Google Apps Device Policy’, though it can’t be added retroactively.

Microsoft Windows Phone
For any Windows Phone 7 or 7.5 device, head to www.windowsphone.com on a desktop or laptop PC and sign in. Then click My Phone. From here, you can locate the phone with GPS, erase all the data, lock the phone and display a message, or change your password. Microsoft also lets you set the phone itself to save its location every few hours; this helps if you lose the phone later and the battery dies, since it will have reported its last known location. To do so, head to Start > App List > Settings and tap Find My Phone.

RIM BlackBerry OS
Research In Motion offers ‘BlackBerry Protect’, a free app that lets you find, lock, or wipe your BlackBerry from a remote location. It also adds daily, weekly, and monthly backup capability for your data. Any BlackBerry Enterprise Server (BES) handset can be erased remotely via the ‘Erase Data and Disable Handheld’ IT administration command over the wireless network. IT admins can also specify if the handset should revert to factory default settings or retain the IT policy it had before.

14
Apr
-(void) handleLongPress:(UILongPressGestureRecognizer *)recognizer  {
    switch (recognizer.state) {
        case UIGestureRecognizerStateBegan:
            [img1 setFrame:CGRectMake(400, 385, 300, 300)];
            [scrollPaging setScrollEnabled:NO];
            [scrollPaging setUserInteractionEnabled:NO];
            break;

And this on the touchesMoved:

UITouch *touch =[[event allTouches] anyObject];

    location=[touch locationInView:self.view];
    img1.center=location;
        return;

14
Apr
- (void)pan:(UIPanGestureRecognizer *)gestureRecognizer {
    UIView *view = [gestureRecognizer view];
    CGPoint startPoint;

    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
        view.backgroundColor = [UIColor redColor];
        startPoint = [gestureRecognizer translationInView:self.view];
    }

    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {

        CGPoint translation = [gestureRecognizer translationInView:view.superview];

        view.center = CGPointMake(view.center.x+translation.x, view.center.y+translation.y);

        [gestureRecognizer setTranslation:CGPointZero inView:view.superview];

    } else if ([gestureRecognizer state] == UIGestureRecognizerStateEnded) {

//        double snapX = round(view.center.x / 110) * 110;
//        double snapY = round(view.center.y / 110) * 110;

        double snapX = round(startPoint.x);
        double snapY = round(startPoint.y);

        view.backgroundColor = [UIColor blueColor];

        [UIView animateWithDuration:0.3 animations:^{
            view.center = CGPointMake(snapX, snapY);
        }];
    }
}

14
Apr
CGPoint ltouch = [gestureRecognizer translationInView:self.view];
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan)
{
      self.pointOnImage = [gestureRecognizer view].center;
}
ltouch = CGPointMake(self.pointOnImage.x + ltouch.x, self.pointOnImage.y + ltouch.y);

[gestureRecognizer.view  setCenter:CGPointMake(ltouch.x, ltouch.y)];

12
Apr

Automatic Reference Counting (ARC) for Objective-C makes memory management the job of the compiler. By enabling ARC with the new Apple LLVM compiler, you will never need to type retain or release again, dramatically simplifying the development process, while reducing crashes and memory leaks. The compiler has a complete understanding of your objects, and releases each object the instant it is no longer used, so apps run as fast as ever, with predictable, smooth performance.

12
Apr

One of the neat features available in iPhone OS 3.0 is the GameKit framework. The GameKit framework contains APIs to allow communications over a Bluetooth network. Using these APIs, you can create peer-to-peer games and applications with ease. Unlike other mobile platforms, using Bluetooth as a communication channel in iPhone is way easier than expected. Hence, in this article, I will show you how to build a simple application that allows two iPhone or iPod Touch devices to communicate with each other.

Regards: http://www.devx.com/

Creating the Project

Using Xcode, create a new View-based Application project and name it as Bluetooth.

All the various APIs for accessing the Bluetooth is located in the GameKit framework. Hence, you need to add this framework to your project. Add a new Framework to the project by right-clicking on the Frameworks group in Xcode and selecting Add, Existing Frameworks. Select GameKit.framework

In the BluetoothViewController.h file, declare the following object, outlets, and actions:

#import

#import

@interface BluetoothViewController : UIViewController {

GKSession *currentSession;

IBOutlet UITextField *txtMessage;

IBOutlet UIButton *connect;

IBOutlet UIButton *disconnect;

}

@property (nonatomic, retain) GKSession *currentSession;

@property (nonatomic, retain) UITextField *txtMessage;

@property (nonatomic, retain) UIButton *connect;

@property (nonatomic, retain) UIButton *disconnect;

-(IBAction) btnSend:(id) sender;

-(IBAction) btnConnect:(id) sender;

-(IBAction) btnDisconnect:(id) sender;

@end

The GKSession object is used to represent a session between two connected Bluetooth devices. You will make use of it to send and receive data between the two devices.

In the BluetoothViewController.m file, add in the following statements in bold:

 

#import "BluetoothViewController.h"

#import

@implementation BluetoothViewController

@synthesize currentSession;

@synthesize txtMessage;

@synthesize connect;

@synthesize disconnect;

Double-click on BluetoothViewController.xib to edit it in Interface Builder. Add the following views to the View window :

  • Text Field
  • Round Rect Button

 

Perform the following actions:

  • Control-click on the File’s Owner item and drag and drop it over the Text Field view. Select txtMessage.
  • Control-click on the File’s Owner item and drag and drop it over the Connect button. Select connect.
  • Control-click on the File’s Owner item and drag and drop it over the Disconnect button. Select disconnect.
  • Control-click on the Send button and drag and drop it over the File’s Owner item. Select btnSend:.
  • Control-click on the Connect button and drag and drop it over the File’s Owner item. Select btnConnect:.
  • Control-click on the Disconnect button and drag and drop it over the File’s Owner item. Select btnDisconnect:.

Right-click on the File’s Owner item to verify that all the connections are made correctly

 

Back in Xcode, in the BluetoothViewController.m file, add in the following statements in bold:

 

- (void)viewDidLoad {

[connect setHidden:NO];

[disconnect setHidden:YES];

[super viewDidLoad];

}

- (void)dealloc {

[txtMessage release];

[currentSession release];

[super dealloc];

}

 

 

Searching for Peer Devices

 

Now that all the plumbings for the project have been done, you can now focus on the APIs for accessing other Bluetooth devices.

In the BluetoothViewController.h file, declare a GKPeerPickerController object:

 

#import "BluetoothViewController.h"

@implementation BluetoothViewController

@synthesize currentSession;

@synthesize txtMessage;

@synthesize connect;

@synthesize disconnect;

GKPeerPickerController *picker;

The GKPeerPickerController class provides a standard UI to let your application discover and connect to another Bluetooth device. This is the easiest way to connect to another Bluetooth device.

To discover and connect to another Bluetooth device, implement the btnConnect: method as follows:

 

-(IBAction) btnConnect:(id) sender {

picker = [[GKPeerPickerController alloc] init];

picker.delegate = self;

picker.connectionTypesMask = GKPeerPickerConnectionTypeNearby;

[connect setHidden:YES];

[disconnect setHidden:NO];

[picker show];

}

The connectionTypesMask property indicates the types of connections that the user can choose from. There are two types available: GKPeerPickerConnectionTypeNearby and GKPeerPickerConnectionTypeOnline. For Bluetooth communication, use the GKPeerPickerConnectionTypeNearby constant. The GKPeerPickerConnectionTypeOnline constant indicates an Internet-based connection.

When remote Bluetooth devices are detected and the user has selected and connected to one of them, the peerPickerController:didConnectPeer:toSession: method will be called. Hence, implement this method as follows:

- (void)peerPickerController:(GKPeerPickerController *)picker

didConnectPeer:(NSString *)peerID

toSession:(GKSession *) session {

self.currentSession = session;

session.delegate = self;

[session setDataReceiveHandler:self withContext:nil];

picker.delegate = nil;

[picker dismiss];

[picker autorelease];

}

When the user has connected to the peer Bluetooth device, you save the GKSession object to the currentSession property. This will allow you to use the GKSession object to communicate with the remote device.

If the user cancels the Bluetooth Picker, the peerPickerControllerDidCancel: method will be called. Define this method as follows:

- (void)peerPickerControllerDidCancel:(GKPeerPickerController *)picker

{

picker.delegate = nil;

[picker autorelease];

[connect setHidden:NO];

[disconnect setHidden:YES];

}

To disconnect from a connected device, use the disconnectFromAllPeers method from the GKSession object. Define the btnDisconnect: method as follows:

-(IBAction) btnDisconnect:(id) sender {

[self.currentSession disconnectFromAllPeers];

[self.currentSession release];

currentSession = nil;

[connect setHidden:NO];

[disconnect setHidden:YES];

}

When a device is connected or disconnected, the session:peer:didChangeState: method will be called. Implement the method as follows:

- (void)session:(GKSession *)session

peer:(NSString *)peerID

didChangeState:(GKPeerConnectionState)state {

switch (state)

{

case GKPeerStateConnected:

NSLog(@"connected");

break;

case GKPeerStateDisconnected:

NSLog(@"disconnected");

[self.currentSession release];

currentSession = nil;

[connect setHidden:NO];

[disconnect setHidden:YES];

break;

}

}

Handling this event will allow you to know when a connection is established, or ended. For example, when the connection is established, you might want to immediately start sending data over to the other device.

Sending Data

To send data to the connected Bluetooth device, use the sendDataToAllPeers: method of the GKSession object. The data that you send is transmitted via an NSData object; hence you are free to define your own application protocol to send any types of data (e.g. binary data such as images). Define the mySendDataToPeers: method as follows:

- (void) mySendDataToPeers:(NSData *) data

{

if (currentSession)

[self.currentSession sendDataToAllPeers:data

withDataMode:GKSendDataReliable

error:nil];

}

Define the btnSend: method as follows so that the text entered by the user will be sent to the remote device:

-(IBAction) btnSend:(id) sender

{

//---convert an NSString object to NSData---

NSData* data;

NSString *str = [NSString stringWithString:txtMessage.text];

data = [str dataUsingEncoding: NSASCIIStringEncoding];

[self mySendDataToPeers:data];

}

 

Receiving Data

When data is received from the other device, the receiveData:fromPeer:inSession:context: method will be called. Implement this method as follows:

- (void) receiveData:(NSData *)data

fromPeer:(NSString *)peer

inSession:(GKSession *)session

context:(void *)context {

//---convert the NSData to NSString---

NSString* str;

str = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Data received"

message:str

delegate:self

cancelButtonTitle:@"OK"

otherButtonTitles:nil];

[alert show];

[alert release];

}

Here, the received data is in the NSData format. To display it using the UIAlertView class, you need to convert it to an NSString object.

 

Testing the Application

Once the application is deployed to the two devices, launch the application on both devices. On each device, tap the Connect button. The GKPeerPickerController will display the standard UI to discover other devices.

When another device tries to connect to you, you will see the popup. Tap on Accept to connect and Decline to decline the connection.

If you are connected, you can now enter some text and start sending to the other device. Data received from another device will be shown in an alert view.

, , ,

12
Apr

To convert an existing project from a non-ARC(Automatic Reference Counting) project to an ARC, you have to do the following :

  1. Go to the Edit menu of the Xcode.
  2. Select Refactor menu from the list of menus which appear.
  3. Now select Convert to Objective-C ARC option from the sub menus which appear.
  4. From the window which appears next, select your project target to convert to ARC.
  5. Click the Check button and Xcode will now ready your app to convert to ARC based project and it will instruct you about what are the modifications in the code that needed to be done to convert the app to ARC.

Once the all issues are solved, the wizard will show the modifications made also.

, , ,