Objective-C Avoid repeating random number

May 25, 2009 § 5 Comments

arc4random() is designed for cryptographic cases. If you use random(), then you would have to seed it with current time. It is random generator.

If you do not want the random number to repeat, use a condition to trigger the random().

int lastNumber;
int rNumber;

While (rNumber == lastNumber)
rNumber = arc4random() % 10;
lastNumber = rNumber;

Advertisements

Objective-C UILabel in clear transparent background

May 25, 2009 § Leave a comment

Use UI Color “clearColor”.

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
[label setBackgroundColor:[UIColor clearColor]];

Install OS 2.2.1 and 3.0 side by side

May 25, 2009 § Leave a comment

If you have SDK 2 installed, then download SDK 3.

In the install, change the location of the install for SDK 3. Click on Developer folder, make a new folder outside Developer folder.

2 Xcode copies on your mac. Start up the Xcode 3.1.3 in the new folder. Load the project and compile it. Run it on OS 3.

Start the Xocde 3.1.2 and rebuild.

Upgrade iphone OS 3.0 beta 5 on iPhone 3G

May 25, 2009 § Leave a comment

Upgrade iphone OS 3.0 beta 5 on iPhone 3G:

  • iTune Check for Updates
  • Must connect to internet to access iTune update server
  • Use built-in USB 2.0 port over hub
  • Use rear USB port rather than front USB port
  • Use latest version of iTunes
  • Try a different computer

There is not enough info about upgrading iphone OS 3.0 beta 5 on iphone 3G. However, you can’t assume the process is the same as iphone 2G.

Upgrade iphone beta 5 on 2G phone (1st Gen) only

May 25, 2009 § 4 Comments

Two out of three developers receive error messages upon installation of iPhone Beta 5 (3.0 (7A312g)) on iPhone. This procedure is confirmed to work for iphone 2G (1st Generation).

  • “ERROR: Updating baseband: file could not be verified”
  • “Bad Build Identity”
  • passcode set for screen locking

Watch out if you are using beta version earlier than Beta 5. Each beta seems to have an expiration date. You must upgrade to the next beta version before the current beta expire. You would need to update from previous Beta to the next Beta version to complete a successful upgrade.

Even if you have Apple Store plan, it is unlikely you would receive Genius help as they are not trained to work on OS 3.0 yet. Apple may not support any iphone problems related to OS 3.0 beta upgrade. It is unlikely that you would be able to exchange for new iphone.

Status: Your iphone may show purple screen or pink screen without option to “Slide for emergency”. It’s iTune logo with usb cable.

Must

  • install latest beta iTune 8.2 (where you download OS 3.0 Beta 5)
  • ipsw copy of firmware

This is how you move the iphone to FDU mode. It is not normal restore mode.

Possible Fix:

Xcode Organizer restore won’t work. You must use iTune beta instead. Don’t skip updating Beta4 before you go on Beta 5. Restore the iphone to beta 4, then do update. Not a restore to beta 5.

Or you can try shorter version

  • hold both buttons for 7 sec then release top button
  • continue to hold home button until iTune recognize the phone

If your beta 4 on iphone is expired, update option on iTune is grayed out.

You can’t restore directly to Beta 5 on 2G / 1st generation iphone. You can restore directly to beta 4 by option-clicking the restore button in iTune 8.2. Select beta 4 file you’ve downloaded. Update from beta 4 to beta 5 by Option-Clicking “Check for updates” button in iTune (Not Restore). Select beta 5 file.

To install OS 3.0 beta 5 into 2G iphone, you need both OS 3.0 beta 4 and beta 5 to complete the process.

To restore back to OS 2.2.1 (you never install beta 3 or beta 4 prior to this)

  • Move iphone to DFU mode
  • Option-Click in iTune on “Restore” button
  • Select 2.2.1 .ipsw
  • Wait until iphone is restored
  • Option-Click on “Check Updates” button in iTune
  • Select 3.0 .ipsw

How to use Google Map with Objective-C Part I

May 24, 2009 § Leave a comment

You want to build an iphone app that open Google map. You would like to show the map in certain ways.

You can consider using Google Map API. Sometimes you would use Google Map Parameters rather than Google API where certain featurse are not supported in API eg Google map displaying driving directions.

It all starts with maps.google.com (.co.uk etc).

=q

Exaction location can be specified as latitude and longitude in

1) decimal form

52.123N,2.456W

52.123,-2.456

2) degrees, minutes and seconds

52 7 22.8N,2 27 21.6W

52 7 22.8,-2 27 21.6

3) degrees and minutes

52 7.38N,2 27.36W

52 7.38,-2 27.36

Any text added in parentheses () is displayed in the info window and sidebar in bold.

Example:

http://maps.google.com/?q=New+York,+NY+(Mapki%A0is%A0a%A0very%A0good%A0Wiki%A0for%A0Google%A0Maps!%A0%A0%A0%A0%A0%A0%A0%A0+The%A0previous%A0line%A0is%A0now%A0sufficiently%A0long!)

The words “to” and “from” cause the driving directions function to be activated.

The word “near” or “loc:” causes the local search function to be activated.

space-ampersand-space (use +%26+ or %20%26%20 in URLs, not +&+ or +&+ otherwise the ampersand gets treated as a separator) can be used between the names of two streets to specify an intersection.

A location can also be specified after an @, in decimal form (@52.123,-2.456). This gives a lower zoom level than using the same values without the at sign. Using this format interferes with other options of the query parameter. The @ sign instead of “near” or “loc:” tends to cause only a single business result to be displayed.To place a custom labeled marker at an arbitrary location,

http://maps.google.com/?q=10+Downing+Str+is+not+here@51.50335,-0.227721

The label can’t be a country name, or no marker will be shown; but it can be empty, when the co-ordinates will be used.

prefix the query with “sky:” to search KML content created for Sky, q=sky:Leo, designed for use with Google Sky and KML output.

near= Can be used as the location part of a query instead of putting the whole thing into q=.

http://maps.google.com/?near=us

g= a address/location, provides extra context for the q param

ll= Latitude,longitude of map centre – Note the order. Only decimal format is accepted.

If this is used without a query, then the map is centred at the point but no marker or info window is displayed.

sll= Latitude,longitude of the point from which the business search should be performed. You could use this to perform an off-centre busness search. Google use it so “link to this page” can record a map that has had the centre moved after performing a business search. When requesting a route map.getBounds().getSouthWest().toUrlValue() returns the same value maps.google.com uses.

spn= Approximate lat/long span. The zoom level will be adjusted to fit if there’s no z= parameter. Use this Mapki tool to find a lat and long.

sspn= Stands for “Screen span”. Map bounds dimensions in Degrees, to calculate this use:
newGLatLng(map.getBounds().getNorthEast().lat() − map.getBounds().getSouthWest().lat(),map.getBounds().getNorthEast().lng() − map.getBounds().getSouthWest().lng()).toUrlValue()

latlng= This is a weird one. It takes three numbers separated by commas. The first two numbers (presumably representing latitude and longitude multiplied by 1000000) are ignored. The third number seems to be a Google internal “Company ID” number for a particular business. E.g. latlng=0,0,14944637421527611642 represents Blackpool Community Church. Specifying this parameter performs a Google Search for pages that reference that business, and displays a tiny map. Other parameters, in particular q=, must have valid contents (but need not relate to the target business) for this to work.

cid= Similar to latlng, but generating a different map size. It takes three numbers separated by commas. The first two numbers (presumably representing latitude and longitude multiplied by 1000000) are ignored. The third number seems to be a Google internal “Company ID” number for a particular business. E.g. cid=0,0,14944637421527611642 represents Blackpool Community Church. Specifying this parameter displays a large map of the identified company location. Other parameters, in particular q=, must have valid contents (but need not relate to the target business) for this to work.

geocode= Concatination of “geocode” encoded values for waypoints used in Directions. Appears when waypoints in “from: blah to: blah” are potentially ambigious. E.g, &saddr=Were+St&daddr=Kings+Hwy+to:Princes+Hwy+to:Princes+Hwy+to:Monaro+Hwy+to:-35.43483,149.112175&hl=en&geocode=FbBP4_0dSEXjCA%3BFWIj4_0dpMDtCA%3BFe4g3_0dunvzCA%3BFfBf0P0dEGzuCA%3BFSoL1_0dtorjCA%3B
is the end result from joining the “geocode” values for each waypoint with %3B.

Map Display

  • t= Map Type. The available options are “m” map, “k” satellite, “h” hybrid, “p” terrain.
  • z= Sets the zoom level.
  • layer= Activates overlays. Current options are “t” traffic, “c” street view. Append (e.g. layer=tc) for simultaneous.
  • view= Can be used to select text view (view=text) or the normal map view (view=map).

Directions

  • saddr= Source address. Use this when asking for driving directions.
Any text added in brackets is displayed in the sidebar in bold.
  • daddr= Destination address(es). Use this when asking for driving directions
Any text added in brackets is displayed in the sidebar in bold.
“+to:” clauses can be appended to the destination to request multiple destination routing, like this daddr=Blackpool+to:Manchester+to:Leeds
Text in brackets can also be added to the “+to:” clauses.
  • mra ?? what does mean this route parameter? known possible values=dm, dpe, cc, ls, …
  • mrcr ?? what does mean this route parameter? known possible values=0
  • mrsp ?? what does mean this route parameter? known possible values=0,1
  • mrad= Additional destination address.
If you’ve got three points in your trip you can use saddr=, daddr= and mrad= instead of “+to:” clauses.
  • dirflg Route type.
    • dirflg=h Switches on “Avoid Highways” route finding mode.
    • dirflg=t Switches on “Avoid Tolls” route finding mode.
    • dirflg=r Switches on “Public Transit” – only works in some areas.
    • dirflg=w Switches to walking directions – still in beta.
  • via= Comma separated list of intermediate addresses for directions, that should be ‘via points’. In the example via=1,3 addresses 1 and 3 will be via points without their own entry in the sidebar. The start (0), the 2nd intermediate (2) and the end (4) will be full addresses.
  • doflg= Distance Units. (Defaults to prevalent units in country of origin.)
    • doflg=ks ??
    • doflg=ptk Outputs directions in metric (km).
    • doflg=ptm Outputs directions in imperial (miles).

Street View

  • cbll= Latitude,longitude for Street View.
  • cbp= Street View window that accepts 5 parameters:
    1. Street View/map arrangement, 11=upper half Street View and lower half map, 12=mostly Street View with corner map
    2. Rotation angle/bearing (in degrees)
    3. Tilt angle, -90 (straight up) to 90 (straight down)
    4. Zoom level, 0-2
    5. Pitch (in degrees) -90 (straight up) to 90 (straight down), default 5
  • panoid= Panorama ID. The ID of the current nearby panorama object. Panorama objects ids are used in the little arrows you can click on in Street View to move you to the next object/property. Eg panoid=eTnPNGoy4bxR9LpjjfFuOw

Tool to find lat and long

Credits:http://mapki.com/wiki/Google_Map_Parameters

iPhone OS 3.0 SDK & Xcode 3.1.3

May 23, 2009 § Leave a comment

It is a very nervous process to install iPhone OS 3.0 especially there are almost no information about this. What to do if things go wrong? How to reverse it?

I am lucky to install iPhone OS 3.0 successfully. Apparently there is no obvious changes as far as Xcode.

If you are on OS 2.2.1, your Xcode version is 3.1.2. If you install OS 3.0, your Xcode version is 3.1.3.

It is very important to read the “About iPhone SDK” 6 page PDF.

The most important upgrade is the iPhone simulator is more accurate and closer to the device.

With Xcode 3.1.3 you can compile project in earlier versions and even the OS 3.0. You have the options to run project on different versions.

Where Am I?

You are currently viewing the archives for May, 2009 at Web Builders.