photo album on iphone - iphone

The below code is for go to photo albums.The below code shows an error. I'm adding the UIImagePickerControllerDelegates like this in my .h file:
#interface My_Pictures : UIViewController <UINavigationControllerDelegate,UIImagePickerControllerDelegates>
But I'm not importing anything in my .m file. Should I include any of the Frameworks? Please give me a clear explanation.
ipc = [[UIImagePickerController alloc] init];
ipc.delegate = self;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else {
ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
[self presentModalViewController:ipc animated:YES];

You have to implement delegate like this in .h class
#interface My_Pictures : UIViewController<UIImagePickerControllerDelegate>
All the best.

UIImageWriteToSavedPhotosAlbum().

Related

Ios MFMailComposeViewController not displaing

I trying to write rhodes native extension extension for opening iOS MailComposer.
Now code "works", but MFMailComposeViewController not displaying and xcode shows warning:
Attempt to present <MFMailComposeViewController: 0x12b60840> on <Iosmailto: 0xc1898d0> whose view is not in the window hierarchy!
I read that UIViewControllers must be in hierarchy, but i can't provide this from Rhodes ruby code or clear-C extension wrapper.
Now i'm trying to present my UIViewController with MFMailComposeController from [UIApplication sharedApplication].keyWindow.rootViewController but mail composer not show yet.
interface from iosmailto.h:
#interface Iosmailto : UIViewController<MFMailComposeViewControllerDelegate>
{
}
#property(nonatomic, assign) id delegate;
//-(IBAction)send_mail:(id)sender;
#end
implementation from iosmailto.m:
#implementation Iosmailto
- (void)viewDidLoad {
[super viewDidLoad];
[self send_mail];
}
- (void)send_mail {
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = self;
[composer setSubject:[NSString stringWithUTF8String:subj]];
NSArray *recipients_array = [NSArray arrayWithObject:[NSString stringWithUTF8String:recipients]];
[composer setToRecipients:recipients_array];
NSString *composerBody = [NSString stringWithUTF8String:message];
[composer setMessageBody:composerBody isHTML:NO];
[composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:composer animated:YES];
[composer release];
} else {
NSLog(#"Device is unable to send email in its current state.");
}
}
/* some unnecessary for this question methods */
#end
And C function defined in iosmailto.m thats called from Rhodes:
// find root vc
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
// find topmost vc
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
iosmailer = [[Iosmailto alloc] init];
iosmailer.delegate = topController;
[topController presentViewController:iosmailer animated:YES completion:nil];
This app is not for AppStore. Hacks is welcome if needed.
Update init for Iosmailto:
- (id)init
{
self = [super initWithNibName:nil bundle:nil];
return self;
}
Update 2 The short version of this code (without UIViewController wrapper) was my starting point. That's don't work too. And this have the same warning and one more:
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
composer.mailComposeDelegate = (id<MFMailComposeViewControllerDelegate>)topController ;
[composer setSubject:[NSString stringWithUTF8String:subj]];
NSArray *recipients_array = [NSArray arrayWithObject:[NSString stringWithUTF8String:recipients]];
[composer setToRecipients:recipients_array];
NSString *composerBody = [NSString stringWithUTF8String:message];
[composer setMessageBody:composerBody isHTML:NO];
[composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[topController presentModalViewController:composer animated:YES];
[composer release];
} else {
}
Use this code to present view controller
[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:composer
animated:YES
completion:nil];
Ok I think the problem is that your UIViewController doesn't have anything in its view property because you aren't using a .xib file to initialize it. See this question which programmatically creates a UIView and assigns it to the UIViewController's view property. I think that's the right way to go. See the implementation of their -(void)loadView method.
Your use-case is also a little strange, since it looks like your Iosmailto UIViewController doesn't have any content, and you're just using it as a wrapper around MFMailComposeViewController--you might consider reimplementing your C method to directly create a MFMailComposeViewController without the unnecessary layer of indirection of this unnecessary UIViewController that doesn't display anything itself.

Send SMS iPhone

I was trying to send SMS from within my app. I wrote this piece of code but it seems not to work.
No crash, no error log, simply nothing happen (of course I tried to log canSendText and the result is 1).
- (void)viewDidLoad
{
[super viewDidLoad];
messageComposer = [[MFMessageComposeViewController alloc] init];
if ([MFMessageComposeViewController canSendText]) {
[messageComposer setBody:#"Messaggio generato da SMSTest"];
[messageComposer setRecipients:[NSArray arrayWithObject:#"3333333333"]];
[messageComposer setDelegate:self];
[self presentModalViewController:messageComposer animated:YES];
}
}
Can anyone explain me what I'm doing wrong?
The problem is that presentModalViewController does not work in viewDidLoad yet as the view is loaded but might not even be on screen yet. If you put your code in viewWillAppear:animated, this should work.
Edit: As per Saphrosit's comment: viewDidAppear: is an even better place to do this.
I use this successfully:
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
controller.messageComposeDelegate = self;
controller.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentModalViewController:controller animated:YES];
Note that it's messageComposeDelegate, not 'delegate' as you do.
Tim
When i try the code on simulator i get an UIAlert saying text messaging is not available, because simulator canĀ“t send messages. Have you checked that your header file is a delegate of MFMessageComposeViewControllerDelegate ?
YourClassName : UIViewController <MFMessageComposeViewControllerDelegate>
//try this ... it will run ..
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
controller.body = #"Hello from Kartik";
controller.recipients = [NSArray arrayWithObjects:#"12356478", nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}

Creating an iPhone contact in Objective-C

I am trying to create a contact in the internal address book. My code is as follows:
in the CreateNewAccountPage.h file:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
....
#interface CreateNewAccountPage : UIViewController <UIScrollViewDelegate,
UITextViewDelegate, MainMenuDelegate, ABNewPersonViewControllerDelegate> {
....
}
- (IBAction)goToContactCreation;
...
#end
In the CreateNewAccountPage.m file:
#import "CreateNewAccountPage.h"
#implementation CreateNewAccountPage
-(void)showNewPersonViewController
{
ABNewPersonViewController *picker = [[ABNewPersonViewController alloc] init];
picker.newPersonViewDelegate = self;
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:picker];
[self presentModalViewController:navigation animated:YES];
[picker release];
[navigation release];
}
-(IBAction)goToContactCreation {
[self showNewPersonViewController];
}
- (void)newPersonViewController:(ABNewPersonViewController *)newPersonViewController didCompleteWithNewPerson:(ABRecordRef)person
{
[self dismissModalViewControllerAnimated:YES];
}
...
#end
The error that I am getting is:
"_OBJC_CLASS_$_ABNewPersonViewController", referenced from:
objc-class-ref-to-ABNewPersonViewController in CreateNewAccountPage.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
If I comment out the lines:
ABNewPersonViewController *picker = [[ABNewPersonViewController alloc] init];
picker.newPersonViewDelegate = self;
...
[picker release];
I no longer receive the error. I am just trying to get a contact to be created. It doesn't have to do with accessing the contact list. I just want a button to create the contact.
Thanks so much!
Add AddressBook.framework, AddressBookUI.framework frameworks to your project.

Using UIImagePickerController in the game

I want to make a game, where the user can touch a picture of a TV and then choose a picture from their photo library.
I had success working with UITextFields, adding them to my EAGLView as subviews But I haven't been able to do the same thing with an UIImagePickerController , which seems the only way to do what I want to do.
Any help is appreciated !
UPDATE
With the suggestion of zpasternack I managed to make the menu appear by adding the UIImagePickerControllerDelegate, UINavigationControllerDelegate and using this method:
- (void) chooseImageFromLibrary {
if( ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] ) return;
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.allowsEditing = YES;
[self addSubview:imagePickerController.view];
[imagePickerController viewWillAppear:YES];
[imagePickerController viewDidAppear:YES];
}
I call the chooseImageFromLibrary method at the start. It shows the interface, but as soon as i hit cancel or choose the app stops.
Can anyone suggest me:
1) How to make the cancel and choose buttons work.
2) How to call the UIImagePickerController whenever I want ( by calling chooseImageFromLibrary again ??).
3) When the user hits choose..Where do i find the UIImage the user just picked to ?, how do i pick it ?
Thanks.
I've never used one over an EAGLView, but UIImagePickerControllers are typically invoked with presentModalViewController, like:
- (void) chooseImageFromLibrary {
if( ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] ) return;
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.allowsEditing = YES;
[self presentModalViewController:imagePickerController animated:YES];
}
Nervermind, problem solved. i just needed to overwrite some functions to make use of the UIImagePickerController.

iPhone: UIImagePickerController Randomly Fails to Take Picture

I use a UIPickerViewController to take picture. It works 80% but seemingly at random it fails to take a picture. In tracing the code I found out that it occasionally goes to
-PinRecordNewTableViewController:viewDidUnload.
That is where it fails because it set nil to all ivars.
#interface PinRecordNewTableViewController : UITableViewController {
}
...
#implementation PinRecordNewTableViewController
...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
...
PinRecordNewPicture *pinRecordNewPicture = [[PinRecordNewPicture alloc] initWithNibName:#"PinRecordNewPicture" bundle:nil];
pinRecordNewPicture.delegate = self;
[self.navigationController pushViewController:pinRecordNewPicture animated:YES];
[pinRecordNewPicture release];
...
}
#interface PinRecordNewPicture : UIViewController
...
#implementation PinRecordNewPicture
...
- (void)picturePicker:(UIImagePickerControllerSourceType)theSource {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = theSource;
picker.allowsEditing = YES;
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (IBAction) takePicture:(id)sender {
UIImagePickerControllerSourceType source = UIImagePickerControllerSourceTypeCamera;
if ([UIImagePickerController isSourceTypeAvailable:source]) {
[self picturePicker:source];
}
What did I do wrong? Did I miss something that causes it to behave "randomly"?
Thanks in advance for your help.
If it called viewDidUnload, then it is very likely that your app is running out of memory. This could be a problem, or just the result of editing large images in phone.
If you're trying to take multiple pictures, save the current one to the Documents area of the app. It frees up the memory. This way, the memory warning can be avoided.
If ViewDidUnload is being called, you might think about saving the relevant state of the app in didReceiveMemoryWarning and restoring it in viewDidLoad. This is done using NSUserDefaults class