Showing posts with label iphone. Show all posts
Showing posts with label iphone. Show all posts

Friday, May 27, 2011

Show timer with seconds using NSTimer on iPhone and Objective C

I am currently developing an iPhone App using X-Code and Objective-C. I had to show a simple timer showing the elapsed number of seconds and minutes. I don’t know much about Objective-C, but from my past experience I knew this task can be easily accomplished using a Timer. The timer should be called every second, and a simple int variable will hold the seconds. The variable is incremented on every call of the timer.
This is how I the timer is defined:
NSTimer *mainTimer = [NSTimer scheduledTimerWithTimeInterval:1 
                  target:self 
                  selector:@selector(timerController) 
                  userInfo:nil 
                  repeats:YES];

Note that the timer is set to be activated every one second and the function that will be called every one second is named “timerController”.

In the “timerController” function I wrote the code that will increment the seconds variable as well as update a label on the screen. In order to update the label with the minutes and seconds I wrote a small function. The function gets seconds and returns a string of the format: “mm:ss” (for example, for input of 90 the function will return: “01:30”. Let’s see the function that returns the time:


- (NSString*)getTimeStr : (int) secondsElapsed {
  int seconds = secondsElapsed % 60;
  int minutes = secondsElapsed / 60;
  return [NSString stringWithFormat:@"%02d:%02d", minutes, seconds];
}

And let’s have a look at the “timeController” function that use it:


- (void)timerController {
  seconds++;
  [[self timeLabel] setText:[self getTimeStr]];
}

The “timeLable” is a UILabel control that is connected with a label that is show on the iPhone screen.


Tuesday, March 15, 2011

iPhone udid Structure

udid is Unique Device Identifier. Every iPhone device has it's own udid.
Other smart phones (Android, Blackberry) also has an id that uniquely identifies the device.
udid value can be easily taken from the class UIDevice by using this simple objective C line:
NSString* udid = [UIDevice currentDevice].uniqueIdentifier;
I am currently working on a mobile installation tracking process. In order to track installations you must compare between the udid of the device when the installed application is first launched.

While conducting tests with udid, I noticed that iPhone udid structure is different when running on X-Code simulator comparing to running on a real device.
Where running on X-Code simulator the value contains the following pattern:

HHHHHHHH-HHHH-HHHH-HHHH-HHHHHHHHHHHH
where "H" stands for Hex number. Note that if there are letters (A-F) they are capital.
For example:
79550EDC-2A86-5BDF-8EE2-219B7FCBD223
When running on a real device the udid value is 40 hex chars. The letters are small. Note that there are no minus ("-") characters used.
For example:

ce43446816952ff4513e1389c5e1d3ac3a856141
I think that the udid is different in the simulator and on a real device because the simulator simply return the udid of the Mac machine and the Mac machine udid string is different than the iPhone device udid.

Monday, October 4, 2010

How to take a Screenshot on iPhone

iPhone allows taking a screenshot very easily. In order to take a screenshot on your iPhone follow these steps:

1) Press the top right button of your iPhone.

2) While holding the top right button, press the main iPhone button.

Here is exactly where you have to press:

Untitled

You can find you screenshot by pressing the “Photos”. It is categorized under: “Camera Roll” album.

Sunday, October 3, 2010

Create folders on iPhone OS 4

iPhone that has OS 4 allows creating folders. If you have several applications that share the same category, you can easily put them under the same folder. This reduces the need to do paging on the iphone, if you have large number of applications. Each folder can hold up to 12 applications. I believe that more than 12 applications will really miss the point of easy and fast access.

The steps need to be done in order to create a folder are:

1) Point with your finger on an application from which you would like to create a folder (hold your finger on the applications). After about a second all the applications (icons) will start rotating and have “x” on their top left. It should look like this:

photo

2) Drag the application from which you would like to create a folder and drop it on another application that you wish to be on that same folder:

photo 3

3) Release your finger or wait a second or 2 and a folder will be opened. A name for the folder will be automatically suggested according to the category of the application for which you wanted to create a folder:

photojj

4) Edit the name of the folder if you want, then press on the folder in order to close it and finally the press the iPhone main button in order to release it from “reordering mode”:

photo lk2

Thursday, September 30, 2010

iTunes software update – Network connection timeout

I wanted to update my new iPhone with a new version. Things seemed to be running fine. But when the download was finished I got this error:

"There was a problem downloading the iPhone software for the iPhone. The network connection timed out"

I tried running the update for several more times with no luck and exactly the same “Network connection timeout” error.

Finally, I got that the problem was due to the fact I was using Kaspersky Anti Virus. Pausing Kaspersky and running the update again solved the problem. I assume other anti viruses might cause the same problem.