Programmatically detect all keyboards which are set in my iPhone settings? - ios

How do I know, how much keyboards enabled into my iPhone keyboard settings.
Even if user downloaded other custom keyboard from app store, still I want in list programmatically.

NSArray *keyboards = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] objectForKey:#"AppleKeyboards"]; // Array of all active keyboards
NSLog(#"List of all keyboards : %#",keyboards);

You can ask current first responder (UITextField, UISearchBar, etc.).
// assume you have instance variable pointing to search bar currently entering
UITextInputMode *inputMode = [self.searchBar textInputMode];
NSString *lang = inputMode.primaryLanguage;

Related

How do I save the text that the user enters into a UITextView

I am basically making a simple notes application. In myViewController I have a UITextView. I want the text that the user types in the UITextView to be saved so that the next time the user opens the app it is still there. How would I go about doing that? I want it to save onto the device so they can type and save a large amount of text.
You could save it easily using NSUserDefaults too.
Add this line of code in your button save event or can add it in your UITextViewDelegate method textViewDidEndEditing: But don't forget to assign delegate of textview using
textView.delegate = self;
Now to store use following code:
NSString *valueToSave = textView.text;
[[NSUserDefaults standardUserDefaults] setObject:valueToSave forKey:#"preferenceName"];
[[NSUserDefaults standardUserDefaults] synchronize];
And to retrieve it back later, use this in your viewDidLoad: or viewWillAppear:
NSString *savedValue = [[NSUserDefaults standardUserDefaults]
stringForKey:#"preferenceName"];
textView.text = savedValue;
Hope it helps.. :)
There are several mechanisms available from iOS for storing data. Which one makes sense for you depends on the size and type of data you want to store and how you need to be able to use it.
A simple place to start might be NSString's writeToFile: (and also Where You Should Put Your App’s Files).

iOS - guided tour with chat bubble-like pop-ups

I want to make a guided tour of my app on the first launch, but not a separated guided tour where I show images of the app. I'd like to have multiple chat-bubbles just like this one:
And when I click somewhere on the screen, the next one pops up. I haven't found a single tutorial for this on the web, so maybe I'm just not using the right keywords...
Anyways, thanks a lot !
You can use an Int e.g. int firstLaunch and save it with NSUserDefaults to detect first launch. Then add a view to the UIView in the story board and make it fill the Application screen and give it a grey color and and transparency.
Then add the images of the bubble in the position you want them in the view.
Below would go in the ViewDidLoad:
firstLaunch = [[NSUserDefaults standardUserDefaults] integerForKey:#"FirstLaunch"];
if (firstLaunch == 0) {
firstLaunch = 1;
[[NSUserDefaults standardUserDefaults] setInteger:firstLaunch forKey:#"FirstLaunch"];
ViewName.hidden = NO;
bubble1Image.hidden = NO;
}

UITextField to hold/save value as I start typing without having me to hit the "done/save" button

I am looking for a code that allows me to have my textfield hold/save value as I start typing. The issue I am facing is that UITextField sets to the previously stored value if I choose to exit the view controller without hitting the done key on the keyboard. I want the UITextField to hold/save the value as I start typing so it holds the value even if I exit the view controller.
you can save the textField Value in NSUserDefault as you type. And retrieve from it.
in ViewDidLoad
-(Void) ViewDidLoad{
NSString *textFieldValue = [[NSUserDefaults standardUserDefaults] valueForKey:#"fieldValue"];
myTextField.text = textFieldValue;
myTextField.delegate = self;
}
//UITextField delegate
- (void)textFieldDidEndEditing:(UITextField *)textField{
[NSUserDefaults standardUserDefaults] setValue:myTextField.text forKey:#"fieldValue"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
I have not tried this specifically on iOS, but I was able to get similar functionality in a Mac app that I was working on by implementing the NSTextFieldDelegate.
#interface AppDelegate : NSObject <NSApplicationDelegate, NSTextFieldDelegate>
Inside of the AppDelegate.m I implemented this part of the protocol:
-(void)controlTextDidChange:(NSNotification *)obj{
This function would run every time text was entered into the field.
Hope this helps.

InAppSettingsKit with multiple localizations

I'm using InAppSettingsKit in my iPad app, including localized Strings for English, German and Japanese. Everything works just fine, but I would like to be able to switch languages in-app, and this does not seem to be supported by InAppSettingsKit. Here's my showSettings method:
// show the inapp settings view
-(void) showSettings
{
IASKAppSettingsViewController *settingsViewController = [[IASKAppSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
settingsViewController.delegate = self;
settingsViewController.showDoneButton = YES;
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:settingsViewController];
[self presentModalViewController:navController animated:NO];
}
so the settings VC is recreated every time, but appears to re-use the language selection from the initial app start.
The user's language selection is written both to my private "language" setting in [NSUserDefaults standardUserDefaults] as well as the "AppleLanguages" array.
Where/how is the old language information cached?
This is the standard behavior of iOS and usually you shouldn't aim to change it. You could probably change it using the AppleLanguages key (or some other key) in NSUserDefaults but AFAIK the current language is always static after app launch.

How to set lock screen , wallpaper and Ringtone programmatically in iPhone?

In iPhone can we set the lock screen, wallpaper and ringtone programmatically?
If Yes, then please let me know how to set them?
This can all be done easily, but will be rejected by Apple.
The ringtone can be changed by altering com.apple.SpringBoard.plist, specifically the ringtone key.
The following code can be used to read the actual ringtone title of custom ringtones (synced by iTunes).
NSMutableDictionary *custDict = [[NSMutableDictionary alloc] initWithContentsOfFile:#"/private/var/mobile/Media/iTunes_Control/iTunes/Ringtones.plist"];
NSMutableDictionary *dictionary = [custDict objectForKey:#"Ringtones"];
NSArray *keys = [dictionary allKeys];
id key = [keys objectAtIndex:indexPath.row];
NSMutableDictionary *customRingtone = [dictionary objectForKey:key];
NSString *name = [customRingtone objectForKey:#"Name"];
cell.textLabel.text = name;
The Wallpapers can be overwritten at:
NSString *homePath1 = #"/private/var/mobile/Library/SpringBoard/HomeBackground.jpg";
NSString *homePath2 = #"/private/var/mobile/Library/SpringBoard/HomeBackgroundPortrait.jpg";
NSString *lockPath1 = #"/private/var/mobile/Library/SpringBoard/LockBackground.jpg";
NSString *lockPath2 = #"/private/var/mobile/Library/SpringBoard/LockBackgroundPortrait.jpg";
These examples were used in one of my Cydia apps. Theres not really much more to them, but these should get you going in the right direction.
The answer by WrightsCS stopped working at some point due to a change in iOS. Unfortunately, this is something you have to live with if you wish to use undocumented features.
If you still need to do this, for non-App Store apps only, this code works in iOS 9.3. It could stop working in any future iOS release, though. (see comment below: no longer working in iOS 10)
#import "SBSUIWallpaperPreviewViewController.h"
#import <dlfcn.h>
// open the private framework dynamically
void *handle = dlopen("/System/Library/PrivateFrameworks/SpringBoardUIServices.framework/SpringBoardUIServices", RTLD_NOW);
UIImage *wallpaper = [UIImage imageNamed: #"background.jpg"];
Class sbClass = NSClassFromString(#"SBSUIWallpaperPreviewViewController");
// we create a view controller, but don't display it.
// just use it to load image and set wallpaper
SBSUIWallpaperPreviewViewController *controller = (SBSUIWallpaperPreviewViewController*)[[sbClass alloc] initWithImage: wallpaper];
[controller setWallpaperForLocations: 3]; // 3 -> set both for lock screen and home screen
dlclose(handle);
You'll need to add the private API header to your project. You can usually find these online with a little searching, for example, here.
In the example above, [SBSUIWallpaperPreviewViewController setWallpaperForLocations:] is called with an argument of 3: 3 indicates the image should be used for both lock and home screens. 1 indicates Lock screen only. 2 indicates Home screen only.
For an explanation of why I open this framework up dynamically, see my related answer here.
I don't have an answer regarding ringtones. This really should be a separate question: completely different APIs at work.
use private api if you can
check PLStaticWallpaperImageViewController

Resources