Thursday, June 3, 2010

currently selected language - iPhone

A titbit now. It is easy to find currently selected language in the iPhone. we can use  NSLocale class to get that. This will give you the Language prefix..(for English - en)

NSString *preferredLang = 
[[NSLocalepreferredLanguages] objectAtIndex:0];


Another way to get the language is by  using the following lines:








NSUserDefaults* defs =
 [NSUserDefaults standardUserDefaults];

NSArray* languages = 
[defs objectForKey:@"AppleLanguages"];

NSString* preferredLang = 


[languages objectAtIndex:0];



Tuesday, June 1, 2010

How does Mozilla makes money?

This question was passing by my mind when ever I open my Firefox browser(very rarely I do it). But I usually get in to the tasks that I was after and forget the question.

But this time I thought, I should not give up and searched in Google. So,

How does Mozilla makes money?

Mozilla Foundation has a deal with the Google, the Internet giant, under which Firefox Browser provides Google as the default search Engine and has its default search page hosted by Google, thereby contributing to the revenues of Google. 

For this Google pays Mozilla foundation. Another source of income is Voluntary contributions. So this is the way by which Mozilla Foundation runs....

SOURCE :http://www.zdnet.co.uk/news/desktop-apps/2005/02/28/google-keeping-the-wolf-from-firefox-door-39189475/

http://www.firefoxanswer.com/firefox/795-firefoxanswer.html

Tuesday, May 18, 2010

Memory Leaks named “open_handle_to_dylib_path”, RegisterEmbeddedAudioCodecs() and CPAThreadStart()


Removing memory leaks in the  App  we develop would be an interesting act .(at least for me). And some times those leaks that have no rationale behind their occurrence can be a nightmare. And I went through this nightmare for over one week. I was gifted by the Instruments tool the following leaks in my app.
  • open_handle_to_dylib_path - Responsible library was CoreGraphics.
  • RegisterEmbeddedAudioCodecs() - AudioToolbox- (This occurred twice.)
For me the Instruments directed me to the line
int retVal = UIApplicationMain(argc, argv, nil, nil);
in the main.m file for first leak. I know there was no rationale behind this problem, but was unsure how I am going to prove it.
And the second problem also was of the same shade pointing me to the line
[audioPlayer play];
in my code.
All these time I was testing my app in iPhone Simulator and I got a way to prove these leaks were untrue.
So I tested my app in the iPhone and got cleared of these leaks. And I was very happy until, I saw another leak from the AudioToolbox library named "CPAThreadStart()". I am on my way to fix it. But  a thread running in cocos2d gave me little bit of relief  that  the leak is present in AudioToolbox. So hoping that the leak is within AudioToolbox I am closing this post.

Friday, May 14, 2010

.png images not loaded in iPhone

Sometimes when you may have some images displayed in your iPhone simulator and when you try to deploy it in iPhone the images may not be displayed.
      One reason which may cause this situation is for the sake of having .png images in your app, you might have changed all the other type of images (jpg or any type ) directly through  "Get Info" option. And at this case your image will be displayed in simulator and not in iPhone.

This service is invalid - iPhone

This error that I was presented by Xcode while trying to run my App in iPhone, led me wildly think that my developer certificate has been either revoked or has past its life.
          But after googling found a result which asked me to restart my iPhone and after this I successfully got rid of the "This service is invalid " error message but was faced with another error message "an unknown error occurred". Then I tried by disconnecting the phone from Mac and restarted the phone. 


And this worked and my  app was installed in the phone.

Monday, May 3, 2010

UITableView backgroundColor in iPad


When you try to change the background color of your UITableView in iPad(not in iPhone), you  will be shocked to find the color of your table  not getting changed. So what to do? Just add the following line
[tableView setBackgroundView:nil];
And voila. It seems that right from iPhone 3.2 you will have to set the background view of your TableView.

Sunday, April 25, 2010

Unicode String in iPhone from webserivce

I had been stuck with the problem of receiving the original Japanese text sent by web service. I was receiving the text in English correctly but instead of receiving the Japanese text I was getting some weird symbols.

And the fix was very simple:
Change the encoding type to NSUTF8StringEncoding when you initialize your Return value with the NSData object..

NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];

NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

Thursday, April 15, 2010

UITextView with border

Yes, you can have your  UITextView with a border and that too with a rounded corner. I was in search of a way to achieve this for over 6 months and could not get it. So did a work around for that, by drawing a view  with lines around and behind the UITextView.

But today I stumbled upon this thread and was able to discover a way to do that.

Any way I will share the code here. If there are any negative implications behind this solution, please share it.

Code:


yourTextView.layer.borderWidth = 1;
yourTextView.layer.cornerRadius = 8; //This is for achieving the rounded corner.
yourTextView.layer.borderColor = [[UIColor grayColor] CGColor];


And don't forget to include the Quartz core framework. 

#import <QuartzCore/QuartzCore.h>

Bye !

Sunday, April 11, 2010

j2me App Development in Mac OS X

Hi Friends,

Those who are in search of an SDK to develop j2me apps in Mac can get the SDK from this Location. And it provides you with a IDE and an emulator. And unlike palm SDK installation, or Blackberry Installation, you don't have any work with Terminal App. And thanks for Sun Microsystem's effort.

And newbies can check this page to have a overview of j2me Application development, CDLC, MIDP, configuration, profiles and packages.

Thursday, April 8, 2010

iPhone Web App: Accessing Webservice with user name and password





Hi Friends,

I was in to development of a Web App for iPhone and after the development got over we had to deploy it in a server. We deployed it. And then the game started.

Our Application internally accessed a webservice from a server which has to be authenticated with the user name and password. And we thought everything would go fine. We tested it in Safari, Chrome and it did work as expected but with a huge delay in displaying the data. Finally we tried in iPhone Safari. And to our frustration, it thrown us unauthorized (401) message. So we tried setting user name and password in open() of xmlHttp object but to no avail in iPhone safari.

Then I tried to setting Authorization Request header  and it threw me a message like "Unsafe Header is set". So  Finally after a period of over 3 days struggle I stumble upon this thread where a ratranch had suggested the solution, where we had to format our URL in the following manner:

http://username:password@your_server_address_and_your_function

Then I tried this option and for heavens sake it worked and I became a relieved man. :)

And to me it seems that this problem is specific to iPhone Safari. I still have not tested it in Android, would test it in Android Browser and update sooner.

Hope this would help some one in search of this solution in web.

Monday, April 5, 2010

iPhone :Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation.

This error when thrown while working on Core Data can make you go insane  ;) .So one situation under which you may encounter this error is that you might have done the following:

1. Added, or deleted or in general modified your Data Model.

2. Then you must have tried to run your application as usual.


You Should try doing  the following and it did helped me.

1. Remove your sqlite file, if you have included any in your project.

2. Delete the entire application from Simulator. You can be more confident if you go the Folder in Library -> Application Support -> iPhone Simulator and delete the Application for the Version of Simulator you are checking.

3. Clean your Targets and Rebuild your Project and run again.

And thats done !!

Tuesday, March 16, 2010

Count No of occurrences of a String or a character

Hi Friends,

I was in a search of a function that would give the number of occurrences of a character or a string in another string and finally I landed in the following solution. If you have any other way to achieve it, please share it.

+ (NSInteger)occurrencesOf:(NSString *)str InString:(NSString *)mainString
{

return [[mainString componentsSeparatedByString:str] count];

}

Thank you.

Friday, March 12, 2010

iPhone OS 4.0 Multitasking

Hi Friends,
This is a good news for iPhone and future iPad users, if it is true as reported in AppleInsider. And as reported this move would silence the critics who always take a dig at apple for not providing the Multitasking. And the main thing to watch out is how is going to achieve it without compromising on battery life.

Lets wait and see whats happening!!

Thursday, March 4, 2010

Rename project File and Target Name in XCode

Hi Friends,

This post is going to help you to change the name of your Project in XCode. And follow the steps given below to achieve the same.

1. Make a copy of your project Folder and delete the build folder if there is one.
2. Rename it to the name you wish to have.
3. Change the name of the .xcodeproj file to the name you wish to have.
4. Change the name of the .pch file.

Now it seems to be fine and when you run you will be blocked by the following error:
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

So lets get to the fifth step.
5. Go to the Targets. Right click on your Target Name and click Get Info.
6. Now go to the Build tab and find the GCC_PREFIX_HEADER in the User-Defined section and you will find the name of the .pch file that you have just renamed and voila.

For renaming the Target, just change the "Bundle display name" in your <project-Name>-info.plist file. And your done...

Monday, March 1, 2010

Palm WebOS- Web Service and Persistent Storage

Hi Friends,

This article will take you through the ways of handling Web Service and Persistent Storage in Palm Web OS.

First let us look at Web Service.

Web Service

1. We can access webservice using two means.
a. Prototype Javascript Framework (Ajax.Request)
b. Native javascript (XMLHTTPRequest)
2. Exchange data can be of any form (JSON, XML, or any of your own format)
3. Currently only asynchronous operations are supported using XMLHTTPRequest, done to preserve UI responsiveness. (I have not checked with the Ajax.Request. If someone has verified it, please share them)
4.Use Prototype Javascript Framework if you don't wish to control every operation yourself and the framework will take care of everything.
5. use Native Javascript if you wanted more control over your code.

Processing JSON:


1. Two ways:
a. eval()- best to avoid, only if source is trusted.
b. JSON parser- faster, never allow malicious script to get executed.

Processing XML:

1. use either DOM or a SAX parser.

Now lets turn towards, Persistent Storage:

Memory is partitioned as three segments:

1. root- for the OS and apps that come by default like calendar, Browser.
2. var -meant for third party Applications, that we are wiling to develop.
3. Media-media partition are visible on the USB volume( Available in your computer, when you plug-in your Palm based phone- pre or pixi).

Three ways to store data:

1. Cookie
2. Depot
3. HTML5

All three forms of data are tied to an application. So, they will be deleted, if you delete your application from the device.

Cookie:

1. Data stored as a key-value pair.
2. It has nothing to do with the Web browser cookie, other than storing data.
3. Maximum of 4KB of data.
4. Can be used to store preferences, simple settings.

Depot:

1. Can store up to 1 MB of data.
2. Size can be extended by using a keyword ext,while creating database.
3. Data stored as Key-value pair.
4. Normal way of creating DB:
var db = new Mojo.Depot({name:”demo”}, onSuccess, onFailure);
5. For extended storage:
var db = new Mojo.Depot({name:”ext:demo”}, onSuccess, onFailure);

HTML 5 database

1. It is a structured database, unlike the first two.
2. Normal way of creating the DB:
this. db = openDatabase("myDB", 1, "My DB", 10000);
3. To store data in Media partition, use
this. db = openDatabase("ext:myDB", 1, "My DB", 10000);


Depot and HTML5 DB operations are asynchronous, unlike the Cookies.

And thats all for this article. Thank you.

Sunday, February 7, 2010

Switch off Monitor in iMac

Hi Friends,

I were searching for an option to switch off my iMac monitor, whenever I am not using it. And there were lot of options provided, some thing goes like using a Utility and lot more. But I stumbled upon this site http://www.ehow.com/video_2179481_turn-off-imac-display.html where they had advised to use CTRL+SHIFT+EJECT to get them done. And really it worked. Cheers! Thanks for the person who suggested it.

Instruction to Follow:
1. Press the ONTROL + SHIFT + EJECT buttons in any order.
2. Ensure that they all are down by the end of the command and set them free from your fingers.
3. And you have your screen slept.

Update:

The first option I have provided CTRL+SHIFT+EJECT helps us take our system to Sleep mode. But to lock your screen in addition to switch-Off the monitor,

1. Press the COMMAND+OPTION+EJECT keys together and your done.

I thank my friend Girija for identifying this combination.

Wednesday, February 3, 2010

Setting up Symbian OS development Environment

This procedure that is to be explained is for Symbian OS development in Windows and not for Mac. I found a link (http://www.randomtype.com/?p=103) which stated there is a Plug-in available for Xcode to develop for symbian OS. But the link specified in the article was broken. So If some one knows a way to set up environment in Mac just share it.

Now lets get in to the procedure:

1. Install the latest ActivePerl available from the following link
http://www.activestate.com/activeperl/downloads/

Note:
Install the Activeperl first before you install the SDK.

2. Install the carbide.c++ IDE from the availble from the Link

http://www.forum.nokia.com/Tools_Docs_and_Code/Tools/IDEs/Carbide.c++/

3. Install the latest SDK availble from the Link

http://www.forum.nokia.com/info/sw.nokia.com/id/ec866fab-4b76-49f6-b5a5-af0631419e9c/S60_All_in_One_SDKs.html


And its done and start developing your applications.:)

Please let me know if any one has trouble in setting up the environment and also share your ideas if you have to overcome any problem you faced.

For Additional info follow the below links

1.http://mobiledevices.kom.aau.dk/development/programming/symbian_c/getting_started/

2.http://wiki.forum.nokia.com/index.php/How_do_I_start_programming_for_Symbian_OS%3F

Tuesday, January 19, 2010

Good News

Hi fellow budding developers,

A good news for you all. I am one of you, who wish to share whatever I experience as a developer. My posts would be regarding Smartphone applications (iPhone, palm OS and Blackberry) . I would meet you all with my first post sooner.

Thank you all.