I have developed landscape mode only project and UIcamera picture controller using take photo but it crashed when camera launched and it will show this reason: Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker animated:YES];
// [self presentViewController:imagePicker animated:NO completion:^{
// [imagePicker setShowsCameraControls:YES];
// }];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: #"No camera available" message: #"Failed to take image" delegate: self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
Try this friends:
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"No camera available" message:#"Failed to take image" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
Related
I have two UIAlertview ,i want to go to different page when i click inside,i create two xib file,and import them in main Viewcontroller,but don't know why can't show it,that is nothing wrong flag when i check~
Here is my code:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"LP01;" message:#"No Connection" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Help", nil];
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:#"LP01;" message:#"No Connection" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Help", nil];
- (void)alert:(UIAlertView *)alertview clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
AViewController *switch1 = [[AViewController alloc]
initWithNibName:nil bundle:nil];
[self presentViewController:switch1 animated:YES completion:NULL];
}
}
- (void)alert1:(UIAlertView *)alertview clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
BViewController *switch2 = [[BViewController alloc]
initWithNibName:nil bundle:nil];
[self presentViewController:switch2 animated:YES completion:NULL];
}
}
Please Help and Thanks~
UIAlertView *firstAlert = [[UIAlertView alloc] initWithTitle:#"LP01;" message:#"No Connection" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Help", nil];
UIAlertView *secondAlert = [[UIAlertView alloc] initWithTitle:#"LP01;" message:#"No Connection" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Help", nil];
// Remember Delegate methods will be same for any number of elements related to it. So whether you have 2 or 3 or 5 UIAlertView's you delegate method will be written only once.
- (void)alert:(UIAlertView *)alertview clickedButtonAtIndex:(NSInteger)buttonIndex {
if(alertview == firstAlert){
AViewController *switch1 = [[AViewController alloc]
initWithNibName:nil bundle:nil];
[self presentViewController:switch1 animated:YES completion:NULL];
}
else if(alertview == secondAlert){
BViewController *switch2 = [[BViewController alloc]
initWithNibName:nil bundle:nil];
[self presentViewController:switch2 animated:YES completion:NULL];
}
}
// Don't forget to call [firstAlert show]; or [secondAlert show]; to show your alert
After sending SMS from my phone(it's working properly) in my project using the MFMessageComposeViewController I can't get back to the app or press cancel. Instead I'm stuck in Apple SMS interface and I can't do anything else then to restart the app. Do I miss something in didFinishWithResult or could it be something else? Thanks
- (IBAction)sendSMS:(id)sender {
MFMessageComposeViewController *controller =
[[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
NSString *str= #"Hi";
controller.body = str;
controller.recipients = [NSArray arrayWithObjects:
#"", nil];
controller.delegate = self;
[self dismissViewControllerAnimated:YES
completion:nil];
[self presentViewController:controller animated:YES completion:nil];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult) result
{
switch (result) {
case MessageComposeResultCancelled:
break;
case MessageComposeResultFailed:
{
UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Failed to send SMS!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[warningAlert show];
break;
}
case MessageComposeResultSent:
break;
default:
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}
I want to create a UIViewController from NSString Name (buttonSelected.viewControllerID), considering class name is the same than storyboardIdentifier how to do that???, currently I have following code for two viewControllers, but I only want to have it in one shot
if ([buttonSelected.typeOfContent isEqualToString:#"AtencionClienteDetalleVC"]) {
if ([[functions removeBlanksFromString:buttonSelected.viewControllerID] isEqualToString:#""]) {
[[[UIAlertView alloc] initWithTitle:#"Notification"
message:[NSString stringWithFormat:#"screen destination must not be empty"]
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil] show];
}
else{
AtencionClienteDetalleVC *viewController = [self.storyboard instantiateViewControllerWithIdentifier:buttonSelected.viewControllerID];
viewController.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:LOGO_COMPANY]];
viewController.itemsCatalog = buttonSelected.viewControllerParameters;
[self.navigationController pushViewController:viewController animated:YES];
}
return;
}
if ([buttonSelected.typeOfContent isEqualToString:#"ListadoVideos"]) {
if ([[functions removeBlanksFromString:buttonSelected.viewControllerID] isEqualToString:#""]) {
[[[UIAlertView alloc] initWithTitle:#"Notification"
message:[NSString stringWithFormat:#"screen destination must not be empty"]
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil] show];
}
else{
ListadoVideos *viewController = [self.storyboard instantiateViewControllerWithIdentifier:buttonSelected.viewControllerID];
viewController.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:LOGO_COMPANY]];
viewController.itemsCatalog = buttonSelected.viewControllerParameters;
[self.navigationController pushViewController:viewController animated:YES];
}
return;
}
just need to set all your buttonSelected.typeOfContent to "ViewController" and then replace your current code for this:
if ([buttonSelected.typeOfContent isEqualToString:#"ViewController"]) {
if ([[functions removeBlanksFromString:buttonSelected.viewControllerID] isEqualToString:#""]) {
[[[UIAlertView alloc] initWithTitle:#"Notification"
message:[NSString stringWithFormat:#"screen destination must not be empty"]
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil] show];
}
else{
NSString *myUIViewControllerClassName = buttonSelected.viewControllerID;
Class myClass = NSClassFromString(myUIViewControllerClassName);
NSObject *myObject = [myClass new];
if( [myObject isKindOfClass:[UIViewController class]] ){
UIViewController *rightViewController = (UIViewController *) myObject;
rightViewController = [self.storyboard instantiateViewControllerWithIdentifier:myUIViewControllerClassName];
rightViewController.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:LOGO_COMPANY]];
[self.navigationController pushViewController:rightViewController animated:YES];
}
}
return;
}
I am trying to launch the MFMailComposer on the iOS 7 simulator and as soon as it comes up it immediately dissmises itself and I get the following error in the debugger.
_serviceViewControllerReady:error: Error Domain=NSCocoaErrorDomain Code=4097 "The operation couldn’t be completed. (Cocoa error 4097.)"
Here is my code
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
case 0:
break;
case 1:{
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:[NSString stringWithFormat:#"%# Totals Report",_teamStats.relationshipTeam.teamName]];
[mailViewController setMessageBody:#"\n\n\n\n\nSent From HoopMetrics" isHTML:NO];
// Attach a doc to the email
NSData* data = [_teamStats.relationshipTeam pdfDataFromString:_teamStats.teamTotalsAsString];
[mailViewController addAttachmentData:data mimeType:#"application/pdf" fileName:#"Totals Report"];
[self presentViewController:mailViewController animated:YES completion:nil];
}
else{
HMAlertView*alert = [[HMAlertView alloc]initWithTitle:#"No Email" message:#"Please, set up an email account on your device" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
}
break;
}
I faced the same problem. Just turn off appearance customization for UINavigationBar or UIBarButtonItem or some another element that MFMailComposeViewController may use.
You can get around this with the following hack using performSelector:
- (IBAction)sendEmail:(id)sender {
[self performSelector:#selector(showEmailComposer) withObject:nil afterDelay:0.0];
}
-(void) showEmailComposer{
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
//Set recipients...other stuff
[mailViewController setToRecipients:recipients];
[mailViewController setSubject:subject];
[mailViewController setMessageBody:body isHTML:isHTML];
mailViewController.title = #"Email VC Title";
mailViewController.mailComposeDelegate = delegate;
[self presentViewController:mailViewController
animated:YES
completion:NULL];
}
After I choose a picture through the UIImagePickerController interface from the Photo Library, the Photo Library view stays displayed, even though I've called dismissModelViewControllerAnimated in imagePickerController:didFinishPickingImage:editingInfo.
Has anyone seen this? These are the three relevant methods I'm using:
- (IBAction)choosePictureFromLibrary:(id)sender {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:#"Error accessing Photo Library" message:#"This device does not support a Photo Library." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingImage:(UIImage*)image editingInfo:(NSDictionary*)editingInfo {
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:#"Picture picked!" message:#"You picked a picture!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
[picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker {
[picker dismissModalViewControllerAnimated:YES];
}
I would have thought that calling imagePickerController:didFinishPickingImage:editingInfo would completely dismiss the Photo Library view, but it doesn't seem to. Is there anything else I have to do to make it go away?
You need to access the viewController of the picker not the picker itself. Try this line instead.
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
You can just call
[self dismissModalViewControllerAnimated:YES];
to dismiss any modal view controller on top of the current view.
This makes sense since you present the view controller by calling:
[self presentModalViewController:picker animated:YES];
Just an update to the answers to this
[self dismissModalViewControllerAnimated:YES];
has been deprecated in iOS 6.0 so you now need to use.
[self dismissViewControllerAnimated:YES completion:nil];
Not a huge change but for anyone that looks at this question and they are using iOS 6.0 they will need an updated answer.
[self presentModalViewController:filePicker animated:YES];
has also been deprecated in favor of
[self presentViewController:filePicker animated:YES completion:nil];