Category Archives: Mac

Samsung Year in Review: Galaxy Triumphs, Apple Losses

Samsung produces a number of products – from kitchen appliances to PCs – but it was the company’s mobile division that made the most headlines in 2012.
The Korea-based company dominated the mobile phone space, introducing several new Galaxy devices throughout the year. But it couldn’t shake one its biggest rivals, Apple, which proved to be a worthy opponent in the courtroom and in stores.
Still, despite all the hysteria surrounding the launch of the iPhone 5 and iPad mini, it was Samsung and its Android-heavy lineup of devices like the Galaxy S III and Galaxy Note II that were the really mobile winners in 2012. Those two smartphones were only introduced in the second half of the year and they have already sold at least 30 million and 5 million worldwide, respectively.

Read more from here..

http://www.pcmag.com/article2/0,2817,2413529,00.asp

Apple fined by China court for copyright violation

A court in China has ordered Apple to pay compensation to eight Chinese writers and two companies for violating their copyrights.

They had claimed that unlicensed electronic versions of their books had been sold on Apple’s online store.

The court ordered Apple to pay them 1.03m yuan ($165,000; £100,000) in compensation, according to the official news agency Xinhua.
… Read more from here.

http://www.bbc.co.uk/news/business-20856199

How to find your Google Plus ID

This is so simple

1. Go to your Google + account (https://plus.google.com/).

2. Click on the Profile icon on the Left.

3. If you look at the URL in the address bar, it should look something like this:

https://plus.google.com/104653270154306099169/posts

4. The long numerical string in the URL is your Google+ ID. Here is CoderzHeaven’s from the URL above:

104653270154306099169/

Google + CoderzHeaven

Using of CCWaves in iPhone

CCWaves is one of the interesting functionalities in Cocos2D iphone.
Check out this following snippet to see how it works.

id my_wavesAction = [CCWaves actionWithWaves:7 amplitude:25 horizontal:NO
                                                               vertical:YES grid:ccg(15,10) duration:10];
[my_sprite runAction: [CCRepeatForever actionWithAction:my_wavesAction n]];

Please leave your valuable comments on this post………………….

How to get Device Orientation in Cocos2D, iPhone in Objective C?

Hello all……
We may need to know that what is your current device orientation.
Using the below code you can do this.

if([[UIDevice currentDevice] orientation] == kCCDeviceOrientationPortrait) {
            NSLog(@"Device is now in Portrait Mode");
}
else if ([[UIDevice currentDevice] orientation] == kCCDeviceOrientationLandscapeLeft) {
            NSLog(@"Device is now in LandscapeLeft Mode ");
}
else if ([[UIDevice currentDevice] orientation] == kCCDeviceOrientationLandscapeRight) {
            NSLog(@"Device is now in LandscapeRight Mode");
}
else if([[UIDevice currentDevice]orientation] ==
  kCCDeviceOrientationPortraitUpsideDown) {
            NSLog(@"Device is now in PortraitUpsideDown Mode");
ss="Apple-style-span" style="font-weight: normal;">
}

Note: If you have to explicitly set the orientation of your phone to any of the above you can set this in the appDelegate.m file. You can put an “||” (OR) symbol in between to set more than one.

Please leave your valuable comments if this post was useful…..

Simulate a Balloon in Box2D, iPhone or ANDROID

Hello………
Sometimes you may want your body to act against the gravity of the world.
One method to do this is described below.
First what you have to do is to make a body in the shape of a circle and give it the image of a balloon as the userdata.

Then in the tick function write this code.
This method of applying the force is called “The antagonist forces method”
By this method we are giving an upward force to only our balloon body irrespective of the gravitational force.
After running the code you will see your body floating in air like a balloon.

for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
   {
        if (b->GetUserData() != NULL) {
               if (b==baloonBody) {
                         b->ApplyForce( b2Vec2(0.0,9.8*b->GetMass()),b->GetWorldCenter()); // here 0.0 is x, 9.8 is y (the gravity)
               }
         }
   }

Note: Try to change the value 9.8 to higher if you have given your world’s gravity as 9.8. It will produce a balloon effect.
Please leave your comments if this post was useful……….

How to Fix ‘Warning : Multiple Build Commands For Output File' ?

Hi,

The following warning, ‘Multiple Build Commands For Output File’ occurs when you try to delete resource files by ‘delete reference’ other than the correct method of‘move to trash’ while deleting files from ‘Resources’ folder of your project. Therefore the Copy Bundle Resources still holds the references of the same file you have deleted and it shows the multiple build commands for the output file after you added the same files over again.

How to Fix? :

Go to the Targets->YourProject->Copy Bundle Resources

From ‘Copy Bundle Resources’ delete those files whose reference are still there or files which shows the warning.

Here ‘YourProject’ is your project name.
:)

How to remove duplicates from NSMutableArray ?

Hi,

For removing or deleting duplicates from a NSMutableArray , use the following lines of code. It will simply check for duplicates elements and get it deleted or removed.


NSArray *tempArr= [urArray copy];

NSInteger idx = [tempArr count] - 1;

for (id object in [tempArr reverseObjectEnumerator]) {

     if ([urArray indexOfObject:object inRange:NSMakeRange(0, index)] !=NSNotFound) {

           [urArray removeObjectAtIndex:idx];
     }

idx--;

}
[tempArr release];

:)

How to create an action when a UITextField is clicked ?

Hi,
Want to invoke an action when a text field (UITextField) is clicked using Objective C? Use the following.

[myTextField addTarget:self action:@selector(textFieldTouched:) forControlEvents:UIControlEventTouchDown];
- (void) textFieldTouched:(id)sender {
        //Here goes your actions on TextField Clicked
}

:)

Creating a Button using Objective C

Hi,

Sometimes you may need to create some buttons to the View using Objective C code rather than using Interface Builder. Here is how you can do that easily and efficiently.
//You can create button with type. Here I am creating a Custom Button

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];

//Then what? Give action to be performed on it!

[myButton addTarget:self action:@selector(newAction:)
forControlEvents:UIControlEventTouchUpInside];

//Giving Background, Frame & Title to the button

myButton.frame = CGRectMake(0, 0, 80, 40);
[myButton setBackgroundImage:[UIImage imageNamed:@"buttonImage.png"] forState:UIControlStateNormal];
[myButton setTitle:@"Go Next!" forState:UIControlStateNormal];

//Finally what?? Add it to the View

[self.view addSubview:myButton];

You can create any number of UIButtons like this! :)

Splitting a string using symbols in Objective C

Hi,
If you want to split a string between a symbol like, ‘.’ or ‘-’ or ‘,’ in Objective C, what to do?
See the code for how to split string in Objective C.

NSString *myString = @”song.mp3”;
NSArray *splitArray = [myString componentsSeparatedByString:@”.”];

This code will split the string ‘myString’ into ‘song’ & ‘mp3′ (separated by ‘.’) and stores in the splitArray indices 0 & 1 respectively. :)

Retrieving Data from NSTextField in Cocoa Mac

Hi,

If you want to retrieve the data a user typed in on a Cocoa Mac application, follow the following steps.
1. You first need to declare a NSTextField variable in .h file

@interface SampleAppDelegate : NSObject {
NSTextField *myText;
}
@property (retain) IBOutlet NSTextField *myText;

2. Then you need to synthesize it for properties in .m file

@synthesize myText;

3. Connect myText with the interface
4. For getting data from this ‘myText’ use the following code

myText.stringValue

Getting name of selected item from NSPopUpButton in Cocoa Mac

Hi,

On many occasions you may need to use a popup button & in cocoa mac you can use NSPopUpButton objects for the same.
While using a pop up button we need to identify the name of the item selected from the pop up list. But how is that done?
You can use the following code for do the same.

NSPopUpButtonCell *nameHere = [sender selectedCell];

nameHere contains the name of your selected item from the NSPopUpButton. :)

Adding Image to a UIImageView using Image URL

Hi,

Sometimes you need to add Image to a UIImageView from the URL of the image you got. In that case, this is how you can add image to the UIImageView.

NSString *picURL= @"http://photobucket.com/yourImage.gif";
NSData *picData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mapURL]];
UIImage* picture = [[UIImage alloc] initWithData:picData];
[pictureView setImage:picture];
[picData release];
[picture release];

Here, pictureView is your UIImageView. :)

Playing sound on the Mac Desktop in Objective C.

There are different ways for playing sound on the Mac in Objective C.

Let’s look at some of the methods..
1. Play by filename.

           NSSound *mySound = [NSSound soundNamed:@"sound"];

if you have no file named “sound” in your application’s main bundle, then it will return nil.

2. Play by pathName

           sound = [[NSSound alloc] initWithContentsOfFile:@"/Volumes/Audio/sound.aiff"
           byReference:YES];

3. Play by URL

        NSURL *soundURL = [NSURL
        fileURLWithString:@"file://~/soundfiles/sound.aiff"];
        NSSound *sound = [[NSSound alloc] initWithContentsOfURL:soundURL

byReference:NO];
Then to play the sound add

         if (![sound isPlaying])
                [sound play];

To pause the sound

               [sound pause];

To stop the sound.

              [sound stop];

To resume the sound

             [sound resume];

Please leave your valuable comments if this post was useful…..

Delete a substring in Objective C, Iphone , Mac………….

This code snippet deletes a substring from a original string..

/** initialize two strings **/
NSString *string = @"This is heaven";
NSString *part = @"heaven";

/** Get the range of the substring in the original string **/
NSRange range = [string rangeOfString:part];

/** Delete the substring from the original string **/
[string deleteCharactersInRange:range];

Please leave your valuable comments………

AlertView with textbox in iPhone, Objective C.

Often we see alerts with text message or title in it.
But actually we can customize alerts. We can place any views inside it.
We can place a textView(TextField) , imageView etc in it.
Take a look at this simple example that places a textbox inside an alertView.

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title goes here!!"
                            message:@"My Message"
                            delegate:self cancelButtonTitle:
                            @"Cancel" otherButtonTitles:@"OK", nil];
UITextField *TF = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[TF setBackgroundColor:[UIColor ClearColor]];
[alert addSubview:TF];        /** adding the textfield to the alertView **/
[alert show];
[alert  release];

Please leave your valuable comments…..

What is Objective C Keyword id ?

Hi,

Objective C uses a special keyword ‘id’.
Let’s see what it is.
Objective C -id- is actually a ‘pointer to an object’. That is ‘id’ can hold a pointer to any objective c object. It doesn’t matter the object’s class.
eg:

NSString *myString = @"Coderz Heaven!";
id newString;
NSString *tempString;
newString=myString;
tempString=newString;

That’s it! It will work out with using ‘id’ keyword. Compiler simply thinks ‘you know what you are doing!’

A word of caution : Remember not to use * while creating id objects! Because that type already know it’s a pointer!