IOS application change language with custom settings screen - iphone

I developed multi language, navigation controller based application. The main menu of the application have also and settings screen at below. User can change to application language with language button pressed. I want to refresh main menu screen and also settings screen language When user changed language But i did not.

NSString *path = [[NSBundle mainBundle] pathForResource:#"nl" ofType:#"lproj"];
NSBundle *bundle = [NSBundle bundleWithPath:path];
NSString *englishWord = #"translate";
NSString *translation = [bundle localizedStringForKey:englishWord value:englishWord table:nil];
NSLog(#"%# = %#", englishWord, translation);
// nl.lproj/Localizable.strings:
"translate" = "vertaal"

Keep in mind, that Apple discourages language selection in the app. The best solution is to just localize your Views and use NSLocalizableString, and just let the language in the app follow the language of the phone's settings.

make a method (which returns a dictionary of language strings loaded from plist) in the AppDelegate.
Whenever user selects a language set the NSUserDefaults accordingly, and call that method in app delegate.
Now use this method in viewWillAppear of every controller and get the desired language dictionary and load your views.
-(NSMutableDictionary*)getCurrentLanguageDictionaryFromResource
{
NSString *defaultPath;
defaultPath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:#"%#.plist",[self getAppCurrentSettingsLanguage]] ofType:nil];
if(languageDictionary !=nil)
{
[languageDictionary release];
languageDictionary=nil;
}
languageDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:defaultPath];
return languageDictionary;
}

You need to restart application, if you want to change language.
For this, you can use local notifications to again restart your application with proper message showing user that your application will get re-started now.
Hope this description helps you......

Related

"Plays Sound" Property of UIButton in Interface Builder

in interface builder there is property of UIButton under Accessibility that says "Plays Sound".
Can any one explain what is this. Actually i am making an application which play sound on every button click and i can disable sounds from setting screen. Will this property of UIButton can help me?
Thanks
You can use [[UIDevice currentDevice] playInputClick]; to play the keyboard input click sound which is available in UIDevice. Check this apple documentation for more details.
You need to do the following for this,
Adopt the UIInputViewAudioFeedback protocol in your input view class.
Implement the enableInputClicksWhenVisible delegate method to return YES.
Do this in UIView class,
#interface MyView : UIView <UIInputViewAudioFeedback>
Then implement enableInputClicksWhenVisible method
- (BOOL)enableInputClicksWhenVisible
{
return YES;
}
If you are facing issues with this, you can check this.
The answer to your original question of whether you can use the Plays Sound 'property' (it's probably not actually a property) to make your buttons play sound is: No. Plays Sound is a 'Trait' that describes the Accessibility of an object (in this case a button) for people who are using VoiceOver (i.e. most likely people who are blind). You can read the documentation here.
hey you want to play sound on button click event then use bellow code also..
-(IBAction)playSound:(id)sender
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"adriantnt_release_click" ofType:#"mp3"]; /// set .mp3 name which you have in project
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}
and use like bellow..
-(IBAction)yourButton_Clicked:(id)sender
{
[self performSelector:#selector(playSound:) withObject:sender];
//your code write here
}
Note: Add AudioToolbox.framework Framework And also import
#import<AVFoundation/AVAudioPlayer.h> in .h file and also add Delegate AVAudioPlayerDelegate in .h file
i hope this help you...

iPhone refreshing tabcontroller and content

I have two problems I am trying to solve, one is refreshing the tab controller itself and the other is refreshing the content of the tabcontroller.
The reason I wish to refresh the tab controller itself is that my application has a web call which returns a JSON which sets up the order of the tabs and also sets up the content of each tab. I have got it so that when you back out of the application and reenter the application the tab controller is refreshed by putting
exit(0)
in the AppDelegates ApplicationDidEnterBackground so that when the user backs out and in again the controller will be refreshed. In the applicationDidFinishLaunchingWithOptions, I have set up a web call which calls the JSON which is then used to set up the tab order. I know this is not a good way of doing this, but for the time being, its the only solution I can think of. How else can I refresh the TabController?
As for the tab content, it is refreshed using using this code
becomeActiveObserver = [[NSNotificationCenter defaultCenter]
addObserverForName:UIApplicationDidBecomeActiveNotification
object:nil
queue: nil
usingBlock:^(NSNotification *note){
[self refresh];
[self viewDidUnload];
}];
I have set this type of code up for each of the 5 tabs. This works very well, but the problem is the content only refreshes when the application is exited and accessed again. The web call will be periodic and I would like it when the web call is made that the content will refresh itself without me having to back out and in to the application again.
For testing purposes I have set up a button in my settings screen (settings screen is just a another view within one of my tabs) that when clicked with read JSON is stored in the iPhone directory which is different from the JSON retrieved from the web call (saves me having to go to the server and keep changing the JSON there). When this button is clicked, it should read this new JSON, update the content and then refresh the view. I have tested this and the JSON is being read and the data is being updated (I set up a button on each screen which would read out the JSON it is using to confirm this) but the view is not refreshing until I exit and enter the application again.
The temp code I have set up in the settings screen to read the JSON stored on the device is
-(IBAction)RefreshApp:(id)sender{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"widgjson" ofType:#"json"];
NSData *myData = [NSData dataWithContentsOfFile:filePath];
NSString *responseString = [[NSString alloc] initWithData:myData encoding:NSUTF8StringEncoding];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex: 0];
NSString *docFile = [docDir stringByAppendingPathComponent: #"json.txt"];
[fileManager removeItemAtPath:docFile error:NULL];
[responseString writeToFile:docFile atomically:NO encoding:NSUTF8StringEncoding
DashboardVC *db = [[DashboardVC alloc] init];
[db refresh];
[db viewDidUnload];
}
At the bottom you can see I tried to call refresh from one of the tabs to refresh one of the views do see if that worked, but no luck. The refresh code only seems to work when you call it from inside the class itself, I can't seem to get it to refresh when accessing it from another class.
When a web call is made, I want every single tab to be refreshed at once. Any ideas on how I would do this?
Would be very grateful if someone could point me in the right direction.
UITabBarController's setViewControllers: animated: method is what you want to use here.
When you receive a notification where you want to re-order the tabs, use that function to pass along the various view controllers owned (and referred to) in your tab bar in an array which is in the order of how you want your tabs to appear.

is there any way by which we can edit a html file in the iphone at the runtime?

HI all,
Is there any way by which we can edit a html file that is in our resource directory and we want to edit some tags in that html first and want to show that html in web view.
Is it possible ??
Thanks ...
NSBundle *bundle = [NSBundle bundleForClass:[self Class]];
NSString *htmlPath = [bundle pathForResource:#"html file name" ofType:#"htm"];
NSString *htmlContent = [NSString stringWithContentOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];
// Do your HTML edits here
[[self webView] loadHTMLString:htmlContent baseURL:nil];
This assumes that you've got a webview property of your view controller. Also, I don't know what the baseURL should be for local files. I know I've done this before, but I don't have access to those files right now. Hopefully this gets you part of the way there.
Yes,
1) Locate and load the file
2) Make your edits
3) Save the file
You'll have to refresh the webview though for the changes to take effect.

MPMoviePlayerController problem when play a movie

i put a movie when my application will lunch . just like gameloft games .
so when application has lunched , movie plays fine but before the move plays .. my FirstViewController xib file show first then moview start to play ! why ?
here is my code :
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"movie" ofType:#"m4v"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *IntroMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
IntroMovie.movieControlMode = MPMovieControlModeHidden;
[IntroMovie play];
}
Your question is a little unclear, but what I think you are asking is why your movie is not playing when the application launches before the user sees the controls and items in your XIB file. If this is correct, then this is the normal behavior as typically the application will launch and only then call the function you have (applicationDidFinishLaunching). There is no guarantee that you will get that function called before the controls have loaded and are viewable on the screen all the time.
It is bad form to start you application with a movie, but if you want to then you have to deal with the fact that there will potentially be a default image or even your controls that you put in your XIB file.
One way to start with a movie, is that you must hide or delete everything in the XIB file so the screen will appear blank when the application loads. Then, when you application calls the applicationDidFinishLaunching function the user will not have seen your application and the first thing they will see is the movie. When the movie is finished playing, you will need to have a notification listener instruct your application to show the controls for your application or switch to another XIB file that has the app controls within it.
I hope this helps.

Audio volume stuck at low level and adjusting volume has no effect?

When I use my app (on the device), the actual volume works OK for a while, but after a few days it seems to get 'stuck' at a low level.
Adjusting the volume rocker has no effect - and it shows 'Ringer' text. I've noticed that other people's apps are similarly affected if they show the 'Ringer' text when adjusting the volume. But apps which don't show 'Ringer' text are not affected by this.
How would I remove the 'Ringer' text and get my app to respond properly to different volumes?
I found some code on Apple's forums which fixes it. You have to use the AVFoundation.framework and put a bit of code into your app delegate. And put an audio file called 'blank.aif' into your project. Basically, it's a hack which prepares a file to play, but then never plays it. This fools the system into thinking that sound is being played all the time, which allows the user to use the main volume control.
#import <AVFoundation/AVFoundation.h>
//...
-(void)applicationDidFinishLaunching:(UIApplication *)application {
//volume control hack
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:#"blanksound" ofType:#"aif"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:soundFilePath];
AVAudioPlayer *volumeHack = [[[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil]retain];
[fileURL release];
[volumeHack prepareToPlay];
// other applicationDidFinishLaunching stuff
}