Showing posts with label IPhone. Show all posts
Showing posts with label IPhone. Show all posts

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, 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 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 !!

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!!