When the accessibility option is turned on the device, we're not able to turn off the closed caption by setting the closedCaptionEnabled option for the AVPlayer instance as we normally would. Is there a way to bypass such option or even to test if it's enabled to lock the CC button if necessary?
You can iterate through each AVPlayerItemTrack and enable/disable it as you wish.
This is how I do in one of my project. I show table of available CC tracks and when the user selects one I iterate through each track, enable the on that user selected and disable rest.
//_selectedTrackIndex = userSelectedIndex;
-(void) setSelectedTrackEnabled {
for (AVPlayerItemTrack * t in [_playerItem tracks]) {
if (counter == _selectedTrackIndex) {
[t setEnabled:YES];
} else {
[t setEnabled:NO];
}
}
}
Related
I have followed the instructions on both these links:
How to play keyboard click sound in custom keyboard?
https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/InputViews/InputViews.html
and done the following:
header:
#interface Key : UIView <UIInputViewAudioFeedback>
implementation:
- (BOOL) enableInputClicksWhenVisible {
return YES;
}
- (void)tapped:(UITapGestureRecognizer *)sender
{
[[UIDevice currentDevice] playInputClick];
[self.delegate keyHit:_title];
}
Yet it is still not working. What have I missed?
Try this code any time you want to play system click sound in a keyboard extension:
+ (void)keyboardClickSound {
// Check system preference for current setting of Keyboard Click Sound.
CFStringRef applicationID = CFSTR("/var/mobile/Library/Preferences/com.apple.preferences.sounds");
Boolean keyExistsAndHasValidFormat;
BOOL enableInputClicks
= CFPreferencesGetAppBooleanValue(CFSTR("keyboard"), applicationID, &keyExistsAndHasValidFormat);
// Note: If the key does not exist because it has never been changed by a user,
// set it to the default, YES.
if (!keyExistsAndHasValidFormat)
enableInputClicks = YES;
// Play Keyboard Click Sound, if enabled.
// Note: If Open Access=Off, no click sound.
if (enableInputClicks)
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
^{ AudioServicesPlaySystemSound(1104); });
}
If your keyboard extension app contains "RequestsOpenAccess" field to YES,
Then keyboard click sound must need "Allow full Access" switch to On from
General > Keyboard > Keyboards > Your_keyboard setting.
If It is Off then you can not play keyboard key sound.
I'm developing a calculator app and would like to add 10 storage registers that the User can store numbers to. The calculator's storyboard has a "STO" button that is pressed when the User wants to store an entry. The next numeric button pressed (button 0, button 1 ... button 9) would signify the register to store the entry in.
The app currently contains the method "STOButtonPressed":
- (IBAction)STOButtonPressed:(UIButton *)sender{
STOButtonPressed = YES;
}
I have a method for entering numbers into the calculator, called digitPressed:
- (IBAction)digitPressed:(UIButton *)sender{
NSString* digit = sender.currentTitle;
[_audioPlayer play];
if(!(self.dotNotation && [digit isEqualToString:#"."])){
if([digit isEqualToString:#"."])
self.dotNotation=YES;
if(self.userIsInTheMiddleOfTyping){
self.displayLabel.text = [self.displayLabel.text stringByAppendingString:digit];
}
else
{
self.displayLabel.text = digit;
self.userIsInTheMiddleOfTyping = YES;
}
}
}
Each number button on the calculator in the storyboard is tagged (button "0" is tag "0", button "1" is tag "1", etc....).
After pressing the "STO" button, I'd like the next button (0 thru 9) entry to be the storage register number. And I'd like to set the storage register number within the STOButtonPressed method. Not sure if that's possible, or how to do it if it is. I currently have several "IF statements" in the digitPressed method for determining the storage register number (not shown here). But that seems very cumbersome and the method has gotten very messy. I'd like to keep all code for the storage feature within the STOButtonPressed method. I've been working this unsuccessfully for many days, and feel I'm missing something. Can someone tell me how to make set the storage register number within the STOButtonPressed method, if that's even possible?
I'm using Xcode 5.
If you have set your button's tags properly, it should be pretty straightforward:
in your properties, add:
#property (nonatomic, assign) BOOL hasPressedSTOButton;
and change this because you don't want confusion between your var and your method name:
- (IBAction)STOButtonPressed:(UIButton *)sender{
self.hasPressedSTOButton = YES;
}
And change your tags to 1-10 instead of 0-9 because you want to make sure you are checking a button with a non-zero tag, and not some other button.
then change your digitPressed like this
- (IBAction)digitPressed:(UIButton *)sender{
NSString* digit = sender.currentTitle;
[_audioPlayer play];
if(!(self.dotNotation && [digit isEqualToString:#"."])){
if([digit isEqualToString:#"."])
self.dotNotation=YES;
if(self.userIsInTheMiddleOfTyping){
self.displayLabel.text = [self.displayLabel.text stringByAppendingString:digit];
}
else
{
self.displayLabel.text = digit;
self.userIsInTheMiddleOfTyping = YES;
}
} else if (sender.tag != 0) {
//store your stuff here. Tags range from 1 to 10. Use sender.tag - 1 if you want the values to range from 0 to 9.
}
}
I added a button to my storyboard, and assigned a music to be played when the button is clicked. I used the event touch up inside
My question is, how can I make the button to toggle the music on and off when it is clicked.
Thanks
==================================================================================
For those of you who are interested in seeing the App, I made a repository on github. Here's the link https://github.com/edwinlimantara/IncrediboxV2. Please contribute, if you feel it is an interesting project.
I tried to make something similar to http://incredibox.com/v2/. Check it out! It is a very cool website.
If you are using AVAudioPlayer you can toggle the music player on button tap like:
if(audioPlayer.isPlaying){
[audioPlayer stop];
audioPlayer = nil;
}else{
// initialize audio player and play
}
You can do like below, say below method is called on button tap event then,
-(IBAction)pushClicked:(id)sender
{
UIButton *mButton = (UIButton*)sender;
if (mButton.selected==NO)
{
[mButton setSelected:YES];
//do your stuff here;
}
else if (mButton.selected==YES)
{
[mButton setSelected:NO];
// do your stuff here
}
}
Better you can use UISwitch rather than button to toggle.
If you want to use UIButton then you can use tags and and two different images.
if(soundButton.tag == 1)
{
if(audioPlayer.isPlaying){
[audioPlayer stop];
audioPlayer = nil;
soundButton.tag = 0;
// Change the button image to Off
}
else{
// initialize audio player and play
}
}
else
{
soundButton.tag = 1;
// Play the music & Change the button image to ON
}
Ours is a health care app. We have a HIPAA-compliant speech recognizer in the app through which all the dictation can take place. The hospitals don't want physicians to accidentally start speaking to the Nuance Dragon server which is not HIPAA-compliant. So, I was looking for ways I could supress the dictation key on the keyboard.
I tried putting a fake button on the Dictation button on the key pad, but on the iPad the split dock concept keeps moving the microphone all over the screen. This does not sound like a reasonable solution. Are there any experts out there who could help me?
OKAY, finally got it! The trick is to observe UITextInputMode change notifications, and then to gather the identifier of the changed mode (Code seems to avoid the direct use of Private API, though seems to require a little knowledge of private API in general), and when the mode changes to dictation, resignFirstResponder (which will cancel the voice dictation). YAY! Here is some code:
Somewhere in your app delegate (at least that's where I put it)
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(inputModeDidChange:) name:#"UITextInputCurrentInputModeDidChangeNotification"
object:nil];
And then you can
UIView *resignFirstResponder(UIView *theView)
{
if([theView isFirstResponder])
{
[theView resignFirstResponder];
return theView;
}
for(UIView *subview in theView.subviews)
{
UIView *result = resignFirstResponder(subview);
if(result) return result;
}
return nil;
}
- (void)inputModeDidChange:(NSNotification *)notification
{
// Allows us to block dictation
UITextInputMode *inputMode = [UITextInputMode currentInputMode];
NSString *modeIdentifier = [inputMode respondsToSelector:#selector(identifier)] ? (NSString *)[inputMode performSelector:#selector(identifier)] : nil;
if([modeIdentifier isEqualToString:#"dictation"])
{
[UIView setAnimationsEnabled:NO];
UIView *resigned = resignFirstResponder(window);
[resigned becomeFirstResponder];
[UIView setAnimationsEnabled:YES];
UIAlertView *denyAlert = [[[UIAlertView alloc] initWithTitle:#"Denied" message:nil delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil] autorelease];
[denyAlert show];
}
}
you can create your own keyboard and set the inputView for the text fields that will accept this dictation. then when they press any keys they will get your keyboard, therefore you dont have to override the keys on the standard keyboard, you will be able to customize the entire thing.
self.myButton.inputView = self.customKeyboardView;
here is an example of an extremely custom keyboard
http://blog.carbonfive.com/2012/03/12/customizing-the-ios-keyboard/
Ray also has a teriffic tutorial on custom keyboards.
http://www.raywenderlich.com/1063/ipad-for-iphone-developers-101-custom-input-view-tutorial
I hope that helps.
I had the same issue and the only way i found that hides the dictation button is changing the keyboard type.
For me changing it to email type seemed to be reasonable:
textField.keyboardType = UIKeyboardTypeEmailAddress;
You could make a subclass of UITextField/UITextView that overrides insertDictationResult: to not insert anything.
This won't prevent the information being sent, but you could then display an alert informing them of the breech.
This is a Swift 4 solution based on #BadPirate's hack. It will trigger the initial bell sound stating that dictation started, but the dictation layout will never appear on the keyboard.
This will not hide the dictation button from your keyboard: for that the only option seems to be to use an email layout with UIKeyboardType.emailAddress.
In viewDidLoad of the view controller owning the UITextField for which you want to disable dictation:
// Track if the keyboard mode changed to discard dictation
NotificationCenter.default.addObserver(self,
selector: #selector(keyboardModeChanged),
name: UITextInputMode.currentInputModeDidChangeNotification,
object: nil)
Then the custom callback:
#objc func keyboardModeChanged(notification: Notification) {
// Could use `Selector("identifier")` instead for idSelector but
// it would trigger a warning advising to use #selector instead
let idSelector = #selector(getter: UILayoutGuide.identifier)
// Check if the text input mode is dictation
guard
let textField = yourTextField as? UITextField
let mode = textField.textInputMode,
mode.responds(to: idSelector),
let id = mode.perform(idSelector)?.takeUnretainedValue() as? String,
id.contains("dictation") else {
return
}
// If the keyboard is in dictation mode, hide
// then show the keyboard without animations
// to display the initial generic keyboard
UIView.setAnimationsEnabled(false)
textField.resignFirstResponder()
textField.becomeFirstResponder()
UIView.setAnimationsEnabled(true)
// Do additional update here to inform your
// user that dictation is disabled
}
Is there a way to cancel a touch for a UIButton? I envision it as something like:
- (BOOL)shouldProcessTouch {
return NO;
}
You know, a place where you can run logic and cancel the touch in certain scenarios. Any ideas?
** EDIT **
For those familiar with event based systems, I'm looking for the equivalent of:
event.stopPropagation();
In most cases, a UIButton will call a method when touched. It may look like this:
-(IBAction)submitButtonPressed:(id)sender{
if(shouldRespond){
//do things normally
}
else{
return; //do nothing
}
}
In this example, shouldRespond is your flag. You should set this flag based on whatever conditions you have.
edit: the flag is a BOOL
Why not just putting button in disabled state?
button.enabled = NO;
Or, disable user interaction for it:
button.userInterationEnabled = NO;