How can I disable re-taking of pictures? - iphone

I use the built-in camera of the Iphone in my apps dans I have two questions.
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
ipc.delegate = self;
ipc.allowsEditing = NO;
[self presentModalViewController:ipc animated:YES];
First, my camera let the user use the picture he took or Retake, I want to take off this option, the user must have only one chance to take his picture.
Second, I want a change the title of the Cancel button on the left, because my app is in french.

For the "Cancel" button, I think you may try with internalization and localization. I don't know exactly how to do.
If you want to control the camera flow, it is harder than the normal way. You have to replace the default control buttons (in the bottom of the camera screen) with your own control. There are 2 methods that you need to do:
First, you need to set showCameraControls to NO: picker.showCameraControls = NO
#property(nonatomic) BOOL showsCameraControls
Then you need to supply your own view: picker.cameraOverlayView = YOUR_OWN_VIEW
#property(nonatomic, retain) UIView *cameraOverlayView

Related

UIPopoverController for iphone not working?

I need to use a UIPopOverController for my iPhone app ,i searched stackoverflow someone said UIPopoverController does not run on iphone iphone device WHY?.when i run on iphone device
i got this error reason: '-[UIPopoverController initWithContentViewController:]
called when not running under UIUserInterfaceIdiomPad.'
-(void)btnSetRemainderTapped:(UIButton *)button
{
setReminderView =[[SetRemainderView alloc]initWithNibName:#"SetRemainderView" bundle:[NSBundle mainBundle]];
setReminderView.contentSizeForViewInPopover = CGSizeMake(setReminderView.view.frame.size.width, setReminderView.view.frame.size.height);
setReminderView.delegate = self;
popOverController = [[UIPopoverController alloc]
initWithContentViewController:setReminderView] ;
CGRect rect = CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/2, 1, 1);
[popOverController presentPopoverFromRect:rect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
can any one help me?
You CAN use popoverController in iPhone apps.
1. Create a category
// UIPopoverController+iPhone.h file
#interface UIPopoverController (iPhone)
+ (BOOL)_popoversDisabled;
#end
// UIPopoverController+iPhone.m file
#implementation UIPopoverController (iPhone)
+ (BOOL)_popoversDisabled {
return NO;
}
#end
2. Import it to your class and use popover in iPhone as usual.
But remember that this is private method and Apple can reject your app. But I know people who use this normally and Apple published their apps.
Edit: As stated by Soberman, since iOS 8 it is possible to present popovers on iPhone using public APIs, so this answer is probably not relevant anymore.
As stated in Apple's documentation on UIPopoverController:
Popover controllers are for use exclusively on iPad devices.
So there is no way to use this class in iPhone application unfortunately. But there are a couple of custom third-party implementations of the functionality provided by UIPopoverController which add iPhone support and more. See https://github.com/50pixels/FPPopover for example.
Edit: There also is another highly customizable popover implementation for both iPhone/iPad worth checking out: https://github.com/nicolaschengdev/WYPopoverController.
Since iOS8 we are now able to create popovers, that will be the same on iPhone, as on iPad, which would be especially awesome for those who make universal apps, thus no need to make separate views or code.
You can get the class as well as demo project here: https://github.com/soberman/ARSPopover
All you need to do is subclass UIViewController, conform to the UIPopoverPresentationControllerDelegate protocol and set desired modalPresentationStyle along with the delegate value:
// This is your CustomPopoverController.m
#interface CustomPopoverController () <UIPopoverPresentationControllerDelegate>
#end
#implementation CustomPopoverController.m
- (instancetype)init {
if (self = [super init]) {
self.modalPresentationStyle = UIModalPresentationPopover;
self.popoverPresentationController.delegate = self;
}
return self;
}
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
return UIModalPresentationNone; //You have to specify this particular value in order to make it work on iPhone.
}
Afterwards, instantiate your newly created subclass in the method from which you want to show it and assign two more values to sourceView and sourceRect. It looks like this:
CustomPopoverController *popoverController = [[CustomPopoverController alloc] init];
popoverController.popoverPresentationController.sourceView = sourceView; //The view containing the anchor rectangle for the popover.
popoverController.popoverPresentationController.sourceRect = CGRectMake(384, 40, 0, 0); //The rectangle in the specified view in which to anchor the popover.
[self presentViewController:popoverController animated:YES completion:nil];
And there you have it, nice, neat blurred popover.
So #Sobermans answer didn't really solve the issue from start to finish for me so I want to detail how I got it done using the docs. That being said I do like the idea of using your own presentation controller subclass to manage all of the customisation you want to exhibit.
1. Create your controller to present
The first step is instantiating the controller you want to present:
let vc: UIViewController = ...
vc.modalPresentationStyle = .Popover
vc.preferredContentSize = CGSize(width: CGRectGetWidth(view.bounds)/2, height: 100)
Now we have a controller with the popover presentation style and an arbitrary content size.
2. Implement adaptivePresentationStyleForPresentationController
By default UIPopoverPresentationController will present on full screen on iPhone so to prevent this behaviour you need to force the adaptive presentation style to none.
First we set the delegate of the popover presentation controller
vc.popoverPresentationController.delegate = self;
Then we implement UIPopoverPresentationControllerDelegate
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return .None;
}
3. Present and configure popup
First we need to call presentViewController and only after that can we configure the popover:
presentViewController(vc, animated:true, completion:nil)
if let popover = vc.popoverPresentationController {
popover.permittedArrowDirections = .Right | .Left
popover.sourceView = button
popover.sourceRect = button.bounds
}
Use a custom popover controller, such as:
https://github.com/sammcewan/WYPopoverController
(this seems to be the best supported one that I have found).
I ended up creating my custom tooltip/popover class.
Can be initalised with any content view and dynamically adjusts it's frame.
Hope it helps.
https://github.com/akeara/AKETooltip
If you want to do it in Swift, I believe the code is the following:
extension UIPopoverController {
class var _popoversDisabled : Bool {
get { return false }
}
}
Edit: It is working in Xcode 6 beta 4 on iPhone with iOs7.1
This is a really interesting (and depressing) thread to read. I can't believe Apple prevents popup dialogs on iPhones, with absolutely no justification.
And, it's true, on iOS 8, if you try to work around this limitation, it'll make your popups appear as a full-screen modal dialog.
The following excellent webpage describes "How Apple Cheats" to let its own iBooks and iTunes apps break its own rules, and allow popups - but just from within their own iPhone apps.
HowAppleCheats
Have a read (warning: it'll make you hate Apple & XCode even more..)
Want to get around the "UIPopoverController called when not running under UIUserInterfaceIdiomPad" error on iOS 8 ?
Simple.
Just go into your .plist file, and change the Bundle ID to "com.apple.itunesu" to make XCode think that your app is actually iTunes.
Then your popup will work fine.
(Sigh.)
The alternative way of doing this is to directly add your UIViewController to your screen.
In this example, I wanted a "helper screen" to appear on top of my iPhone screen. It's a UIViewController, it is stored in it's own .xib file, and it has a few lines to add a pretty border:
- (void)viewDidLoad {
[super viewDidLoad];
// Give our popup a pretty curved border
self.view.layer.borderColor = [[UIColor blueColor] CGColor];
self.view.layer.borderWidth = 1.0;
self.view.layer.cornerRadius = 8;
}
To display it, I simply create an instance of this UIViewController, add it to my screen, then center it:
-(void)showHelperScreen
{
if (self.helperScreen == nil)
{
// Add the popup UIViewController to our screen
self.helperScreen = [[HelperViewController alloc] init];
[self.view addSubview:self.helperScreen.view];
}
// Center the popup in the middle of the screen
CGSize screenSize = [[UIScreen mainScreen] applicationFrame].size;
self.helperScreen.view.center = CGPointMake(screenSize.width/2, screenSize.height/2);
}
Of course, I also needed to add some code to make the popup disappear when the user taps outside of it, but this does at least show that you can (safely) display popups on an iPhone, even if your app isn't specifically called iTunes or iBook.
Voila.
Hope this helps, and if anyone needs me, I'll be back in my safe, happy place (Visual Studio, in other words).

UIButton stopped responding during development

I have a couple of buttons in a view. These were tested a few days ago and were working fine. Today for some reason they stopped working. The buttons are custom, with an image. They are connected to an action like:
- (IBAction)walkTurnByTurn:(id)sender {
NSLog(#"Clicked Turn By Turn Walk");
CLLocationCoordinate2D destination = self.loadOficina.coordinate;
MKPlacemark *endLocation = [[MKPlacemark alloc] initWithCoordinate:destination addressDictionary:nil];
MKMapItem *endingItem = [[MKMapItem alloc] initWithPlacemark:endLocation];
[endingItem setName:self.loadOficina.title];
NSMutableDictionary *launchOptions = [[NSMutableDictionary alloc] init];
[launchOptions setObject:MKLaunchOptionsDirectionsModeWalking forKey:MKLaunchOptionsDirectionsModeKey];
[endingItem openInMapsWithLaunchOptions:launchOptions];
}
I deleted the button and created it again, connected it to the action. It is enabled, user interaction enabled as well. It looks like it is just not responding to touches at all because it doesn't change color when clicked.
Any ideas what might have happened?
It's probably out of the bounds of its superview. If the superview frame is 0,0,100,100 you can add the button as a subview that starts at, say, 200,200. It will show up on the screen but it won't respond to events. This is happening to a lot of people with iPhone 5 layouts. They accidentally hardcode the window to 320x480. The controls show up at y positions > 480 but they aren't interactive.

How to set title in the MFMailComposerViewController?

I am trying to set the title of MFMailComposerViewController , which is a subclass of UINavigationController.
I am using these following ways :
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
[picker.navigationController navigationItem].title = #"Send Mail";
[[picker navigationItem] setTitle:#"Send Mail"];
But I am not able to set the Title.
Am i doing it wrong ??
Is there any other method to do so ??
Thanks
The title is updated whenever the subject changes. You cannot change the title programmatically within AppStore restrictions. You may use -setSubject: to initialize the subject.
(A bad way to solve this is to create a very high-level window with a label that covers original title. This is very difficult to make this work with orientation change.)

navigationItem.prompt & UIImagePickerController

Is it possible to make calls to navigationItem on a UIImagePickerController? Specifically, the image picker? Below I've linked an image of what I'm trying to achieve ( screen shot taken from another app doing the same thing). Once the user selects an image from the picker the navigationItem.prompt is set and, though I think it might be a HIG violation, the right bar button is changed from the standard cancel button. I can set the prompt on a "normal" view no problem with:
self.navigationItem.prompt = myString;
But this does not seem to work when I try to use it in the context of a picker with:
myPicker.navigationItem.prompt = myString;
I've tried using it when the picker is created and also in didFinishPickingMediaWithInfo: which is really where I need to set it as I'm letting the user select multiple images instead of dismissing the picker as soon as one image is selected. Nothing seems to work.
Here's a image of the desired behavior:
http://i51.photobucket.com/albums/f353/zoso5th/after.png
Someone answered this for me on the Apple dev forums:
UINavigationBar *bar = picker.navigationBar;
UINavigationItem *navItem = bar.topItem;
navItem.prompt = #"Some new prompt";
I wasn't correctly accessing the navbar.
Someone answered this for me on the Apple dev forums:
UINavigationBar *bar = picker.navigationBar;
UINavigationItem *navItem = bar.topItem;
navItem.prompt = #"Some new prompt";
I wasn't correctly accessing the navbar.
Use the code after calling 'presentModalViewController'.....like below...
[controller presentModalViewController:imagePickerController animated:YES];
UINavigationBar *bar = picker.navigationBar;
UINavigationItem *navItem = bar.topItem;
navItem.prompt = #"Some new prompt";

Force scope bar below UISearchBar

I have a UISearchBar and UISearchDisplayController, everything works great but my scope selector displays beside the text field instead of below it. I know that this is the expected action when the device is in landscape, but since I have the UISearchBar in the master view of a UISplitViewController it ends up looking like this:
Is there any way to force the scope bar to display below the text field in all interface orientations (I know that this works nicely in Mail.app on the iPad, so its possibly, but who knows if Apple decided to hide the option to do so)
This is not part of the public API. Hopefully it will be added in the future. It can be accomplished using Private APIs, looking through a UIKit class dump will help you there.
Good luck!
edit: Note that using private APIs can get you rejected from the app store, as most people already know.
I used the UISearchDisplayDelegate to show and hide the scope bar.
-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
{
[controller.searchBar setShowsScopeBar:YES];
}
-(void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller
{
[controller.searchBar setShowsScopeBar:NO];
}
Don't use private APIs. Instead, follow Apple's recommendation from IOS User Interface Guidelines:
When a search bar is present, a scope bar can appear near it. The
scope bar displays below the search bar, regardless of orientation,
unless you use a search display controller in your code (for more
information on the way this works, see UISearchDisplayController Class
Reference). When you use a search display controller, the scope bar is
displayed within the search bar to the right of the search field when
the device is in landscape orientation (in portrait orientation, it’s
below the search bar).
This worked for me using storyboards.
Why not just set up your search bar programattically? Here's what I'm using on my current project. It hides the search bar until the user scrolls up, and the scope bar is loaded below the text field when they start typing items. From there just filter as usual:
- (void)setupSearchBar {
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
self.searchBar.showsScopeBar = YES;
self.searchBar.scopeButtonTitles = [NSArray arrayWithObjects:#"Users", #"Groups", nil];
self.tableView.tableHeaderView = self.searchBar;
CGPoint offset = CGPointMake(0, self.searchBar.frame.size.height);
self.tableView.contentOffset = offset;
self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar
contentsController:self];
self.searchController.searchResultsDataSource = self;
self.searchController.searchResultsDelegate = self;
self.searchController.delegate = self;
}
call [self setupSearchBar]; in viewDidLoad you're off to the races.