UIImagePickerController on iOS 7: Square mode? - objective-c

I'm working with iOS 7 now, trying to get the UIImagePickerController to let the user select a square mode since it's a feature in iOS 7 now. Is there something I need to enable to allow this swipe? Relevant code posted below, though it's pretty standard.
UIImagePickerController *cameraView = [[UIImagePickerController alloc] init];
cameraView.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraView.delegate = (id)self;
[self presentViewController:cameraView animated:YES completion:nil];
I've been scouring the messy iOS 7 documentation that's available, but I can't even tell if they changed the developer library at all - I don't see ANYTHING new in it.

set allowEditing to YES.
from the result dict use the key UIImagePickerControllerEditedImage
then you will have the squared image.
i find no way to let the user select, which format he want :(

I looked at the iOS 7 header for UIImagePickerController in Xcode, and I do not see new API for 7.0 or a square photo mode. The square photo mode appears to be a feature of the app, not of UIImagePickerController.

Related

AVFoundation Speech Synthesis on iOS 8 and XCode 6

I am having problems using AVSpeechSynthesis on iOS 8.0.2 and XCode 5. I tried it on the simulator and got a "Speech initialization error: 2147483665". I then tried it on my iPhone 5 and got no error but no speech.
In my .h file I import
import
and have #property (strong, nonatomic) AVSpeechSynthesizer *synthesizer;
In my .m file I synthesis the synthesizer
I have AVFoundation referenced in my frameworks
On my viewDidLoad I do the following
self.synthesizer = [[AVSpeechSynthesizer alloc] init];
self.synthesizer.delegate = self;
Later on in my code to control what is said I do the following
AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:dialog];
utterance.rate = AVSpeechUtteranceDefaultSpeechRate;
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:#"en-au"];
[self.synthesizer speakUtterance:utterance];
I have CCViewController : UIViewController in my view controller.
Does anyone know what is wrong? Does AVFoundation work in iOS 8?
I saw a similar post on stack overflow which said to initialize my speaking #" " but that did not work.
Any help would be appreciated.
Thanks,
Greg
What you have should work with a small tweak, I think (see below), but only on a device and not the simulator. I replicated the same error message when I try to run your code or code I have that uses AVSpeachUtterance in the simulator. Not sure if this is a bug or just a limitation of the simulator. To get things working, try commenting out the line:
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:#"en-au"];
Does it work then? Without this line of code things working as they should for me on an iPhone 5 (8.0.2), however if I use any of the codes language codes shown here (What are the BCP-47 voice codes available for iOS 7 AVSpeechSynthesisVoice?), no text is spoken. The only way I can get things to work when I explicitly set the language is if I use #"en-GB", which is also the language the phone is configured for in settings. I can use another language code if I change the language of my phone in settings, say to US english and #"en-US".
As an FYI, the bug that required an initial bit of dummy text, i.e. #" " to get things working seems to be fixed in 8.0.2

How to add the iOS "Open In..." feature to an app

I would like to know how to present the "Open In..." Action Sheet (iPhone) / Popover (iPad) from my app, preferably an IBAction
I would hope that it'd be similar to declaring a file type then creating the view and opening the app selected by the user, but I know it is more complicated then that.
I realize that a similar question has been asked on StackOverflow, but I cannot make sense of the answer that was accepted: How to use "open in..." feature to iOS app?, and I have found some Apple Documentation on Document Interaction Programming. But, I can't really make sense of these.
Create a UIDocumentInteractionController by using the interactionControllerWithURL: class method (pass the URL of the file you want to open in another app).
Then call either presentOpenInMenuFromRect:inView:animated: or presentOpenInMenuFromBarButtonItem:animated:. The controller takes care of presenting the popover with available apps for that file type and opening the selected app.
If you want to know when the menu was dismissed and which app was selected, you need to implement the UIDocumentInteractionControllerDelegate protocol.
omz makes some good points on how to do that in his answer, however this procedure is much easier with the introduction of new APIs in iOS 6. Here's a simple and efficient way to show the UIActionSheet Open-In-Menu in iOS 6 and up:
NSArray *dataToShare = #[contentData]; //Or whatever data you want to share - does not need to be an NSArray
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];
Also, if your app is compatible with versions of iOS lower than 6.0 you may want to check if the Share Service exists:
if ([UIActivityViewController class])
Once you present the sheet, iOS will automatically handle the rest for you. It will display a beautiful uiactionsheet with icons showing each app or service the user can open / share your data with:
Note that depending on the contents of the data, iOS will show different services in the Share Sheet
EDIT: The method above shares the file content, but not the file itself. Refer to omz's answer for more on that.
I've personally never had to do this, but your answer can most certainly be found in this Apple Documentation: http://developer.apple.com/library/ios/#documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/PreviewingandOpeningItems.html#//apple_ref/doc/uid/TP40010410-SW1.

How does iBooks do this?

I am currently displaying text in a uiwebview. However, I would like to allow a user to select text and perform some action with the selected text (google it). Apple has done this sort of thing with iBooks. When you click on a word you can choose to look up the word in a dictionary. How can I do the same thing with Webview?
UIMenuController seems to be what I need to look at. But I couldn't find any sample code on how to do this. I'm new to iPhone development please help.
Starting in iOS 3.2 you can use UIMenuController to add additional UIMenuItems to the system menu that appears when selecting text in a UIWebView. Here's a simple example:
- (void)viewDidLoad {
[super viewDidLoad];
UIMenuItem *defineItem = [[[UIMenuItem alloc] initWithTitle:#"Define" action:#selector(defineSelection:)] autorelease];
[[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObject:defineItem]];
}
- (void)defineSelection:(id)sender {
NSString *selection = [webView stringByEvaluatingJavaScriptFromString:#"window.getSelection().toString()"];
// Do something with the selection
}
Apple describes how this works in the Adding Custom Edit Menu Items section of the Device Features Programming Guide.
This recent blog post from a developer would seem to suggest that at least in the iPad iOS branch, some iBooks functionality is based on private APIs.

How do I duplicate iPad display over TV out?

Is it possible to simply duplicate ipad display to TV out (assuming both have same resolution)?
Code like this doesnt seem to work (it is a pretty naive implementation)
int i=0;
for (UIScreen *screen in [UIScreen screens])
{
if(i>0)
{
UIWindow* extWindow = [[UIWindow alloc]init];
extWindow.screen =screen;
[extWindow addSubview:viewController.view];
[extWindow makeKeyAndVisible];
}
i++;
}
[window addSubview:viewController.view];
[window makeKeyAndVisible];
Code like this doesnt seem to work (it
is a pretty naive implementation)
This code looks like a mishmash. I haven't used external screens before, but your inner if block is creating anonymous UIWindow objects, assigning a property, and then leaking them at the end of the block (no release) -- and that definitely won't do what you intend.
You should consult the iPad Programming Guide, specifically, Support for External Displays and Projectors, which summarizes how your code should be written.
If you need this for a demo presentation, then there are few apps that will duplicate the screen for you while running your app like TVOut, TVOut2, Screenspltr. However there is a catch, these apps are not approved by Apple therefore are not in the app store, in order to install them you'll need to jailbreak it and it comes with the involved risks. However for a quick dome it is probably the best solution.

Can I disable UIPickerView scroll sound?

I want to disable the annoying clicks that the UIPickerView generates upon scrolling up and down. Is there a way to do this? I want to play short sounds for each item that the picker view lands upon. It gets ruined by the built in sound.
I understand that the picker sounds can be turned off globally by switching off the keyboard sounds in iPhone/iPod settings. But is there a way to programatically do this?
Any help will be much appreciated!
Thanks
I've been struggling with a UIPickerView sound issue, and even though it's only partially relevant to the original question, I'm posting the problem/solution here because this topic keeps coming up in my search results so I think anyone else in the same boat may end up here too…
I needed to initialize a UIPickerView to restore the currently selected row from saved data. Simple, right? In viewDidLoad, just call the selectRow:inComponent:animated method of UIPickerView:
[myPicker selectRow:currentRowIndex inComponent:0 animated:NO];
This works as expected, but has a side effect that it generates a single "click" sound as if the user had scrolled the control. The click sound only occurs when running on a device (not the simulator), and only if the device has iOS 3.x installed (I tested with 3.1.3 and 3.2). This was apparently a bug in iOS that was fixed starting with iOS 4.0. But if you need to target Gen1 iPhone, you're stuck with iOS 3.1.3 where this problem is present.
I discussed the issue with Apple DTS, but they were unable to suggest any workaround other than upgrading to 4.0. I asked if they would make an exception and permit the use of the undocumented setSoundsEnabled mentioned above (which does actually solve the problem). The answer was, "There are no exceptions."
After some additional detective work, I discovered that you can prevent the sound from occurring by temporarily removing the UIPickerView from the superview, call selectRow, then re-add it to the superview. For example, in viewDidLoad:
UIView *superview = [myPicker superview];
[myPicker removeFromSuperview];
[myPicker reloadAllComponents];
[myPicker selectRow:currentRowIndex inComponent:0 animated:NO];
[superview addSubview:myPicker];
This gets rid of the extraneous click sound without using undocumented/private APIs so should pass Apple's approval process.
After using this specific undocumented api for over a year on the App Store Apple finally asked me to remove it from my App. It is very frustrating for audio apps to have that damn click sound. The best advice is to share with users that the picker sound can be disabled globally in the settings application under "Sounds" and setting "Keyboard Clicks" to "Off". I also strongly recommend visiting https://bugreport.apple.com/ and filing a bug for UIPickerView, as it can cause distortion in audio applications when the picker click is played.
they have just rejected an app of mine because the use of undocumented api's...thats one of them.
Someone I know says he got this past the App Store review just last week:
// Hide private API call from Apple static analyzer
SEL sse = NSSelectorFromString([NSString stringWithFormat:#"%#%#%#", #"set",#"Sounds",#"Enabled:"]);
if ([UIPickerView instancesRespondToSelector:sse]) {
IMP sseimp = [UIPickerView instanceMethodForSelector:sse];
sseimp(self.thePicker, sse, NO);
}
There is an undocumented way (I'm actually not sure if it is still available in iphone 3.0) but here it is any way
#import <UIKit/UIKit.h>
#interface SilintUIPickerView: UIPickerView
{ }
- (void) setSoundsEnabled: (BOOL) enabled;
#end
use this subclass instead and call [view setSoundsEnabled: NO]
I'm interested in knowing how it goes in the latest SDK, give it a shot and let us know.
Could this trick work? Someone was able to suppress the camera shutter sound effect by playing an inverted copy of the sound at the same moment: https://stackoverflow.com/a/23758876/214070
Maybe this not the answer for this particular question, but I had a similar problem - set minimumDate for datePicker, and I wanted set it without annoying "click" sound. After some time found very simple solution:
datePickerCustomTime.minimumDate = [[NSDate date] dateByAddingTimeInterval:300]// min time to set = now + 5 min
[datePickerCustomTime setDate:[[NSDate date] dateByAddingTimeInterval:300] animated:NO];
I found small quickie solution for this try below
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, yPickerView, VIEW_WIDTH, PICKERVIEW_HEIGHT)];
pickerView.delegate = self;
pickerView.dataSource = self;
pickerView.showsSelectionIndicator = YES;
pickerView.alpha = 0.8f;
pickerView.tag = fieldTag;
[pickerView selectRow:pickerViewSelectedIndex inComponent:0 animated:NO];
set the animated:NO for selectRow: method