The related code below worked perfect when i was building for iOS 7, but it seems now in iOS 8, it's not working properly.
By properly, I mean in the sense where it's not actually sending the file or whatever to the chosen app.
Example: If I selected Mail, it would open the mail app with the image or zip I chose in the text field. Now it won't send and it takes forever to call/dismiss the UIDocumentInteractionController.
What am I doing wrong?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
NSString *fileName = [directoryContents objectAtIndex:indexPath.row];
NSString *path;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:#"Downloads"];
path = [path stringByAppendingPathComponent:fileName];
documentController = [[UIDocumentInteractionController alloc] init];
documentController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path]];
[documentController setDelegate:self];
[documentController presentOptionsMenuFromRect:CGRectZero inView:self.view animated:YES];
[documentController retain];
}
I have been playing around with the UIDocumentInteractionController and Delegate trying to fix a similar problem, the controller opened-up alright but selecting an application caused it to close without doing anything, my delegate method documentInteractionControllerDidDismissOpenInMenu also run alright afterwards.
In the console i got the notification enabledRemoteNotificationTypes is not supported in iOS 8.0 and later.
It turns out that this problem will accrue when one of these delegate methods is called :
documentInteractionControllerDidDismissOpenInMenu
documentInteractionControllerDidDismissOptionsMenu
(and possibly others, i did not check all of them)
I did not find any comment in the IOS Development Library or the UIDocumentInteractionController.h about these methods not supported for IOS 8.1 but at this point i cant find any other explanation.
Solution :
i replaced documentInteractionControllerDidDismissOpenInMenu
with didEndSendingToApplication
and it solved the problem for me.
Related
My viewController has the following method, which gets called after an image gets selected via a UIImagePickerController. I'd like to upload the selected image to my web service, however, when attempting to follow the samples provided by RestKit I get the following error:
No visible #interface for 'RKObjectManager' declares the selector 'multipartFormRequestForObject:method:path:parameters:constructingBodyWithBlock:'
I'm using the most recent version of restkit, and right clicked went to definition to check the signature which seems correct.
It is worth noting that AFMultipartFormData is not highlighting in XCode. I tried including #import AFNetworking/AFHTTPClient.h but it still shows as plain text, which i suspect might be the problem?
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[imageView setImage:image];
ImageRecord *imageRecord = [ImageRecord new];
NSDictionary *params = #{#"param1" : #"value1",
#"param2" : #"value2",
#"param3" : #"value3"};
// Serialize the Article attributes then attach a file
NSMutableURLRequest *request = [[RKObjectManager sharedManager] multipartFormRequestForObject:imageRecord method:RKRequestMethodPOST path:#"stuff" parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:UIImagePNGRepresentation(image)
name:#"article[image]"
fileName:#"photo.png"
mimeType:#"image/png"];
}];
RKObjectRequestOperation *operation = [[RKObjectManager sharedManager] objectRequestOperationWithRequest:request success:nil failure:nil];
[[RKObjectManager sharedManager] enqueueObjectRequestOperation:operation]; // NOTE: Must be enqueued rather than started
[self dismissViewControllerAnimated:YES completion:NULL];
}
Thanks for any pointers!
That method is multipartFormRequestWithObject: (note that the method name you're using has ForObject). You shouldn't need to import any additional headers.
I'm using magical record with Core Data.
In my app I have just one entity with some string attributes. Now, I would like to add an image to this entity, but I don't have any idea of how to do that using magical record. I searched but haven't found anything on the web. In my app all the data is inserted by the user, so also the image, by the camera or the photo library.
How do I store images using Magical Record and Core Data?
Just store the image in the documents folder of the app and save a string with the file url in the core data entity.
What you're trying above can be done easily. Best advice i can give you is make a new sample project just to save and retrieve image from the CoreData database. That way you know exactly how the process works. If you try to embed this functionality in your current project you might loose track of what happening where.
This is very quick example, i'll expect you to import the Delegates in your .h files yourself etc.
First initiate the UIImagePicker via button
-(IBAction)pickImage:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES];
}
Once the image is selected, you can display it on the button using one of the delegate methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo
self.imageButton.imageView.image = selectedImage;
To save it to CoreData assign your UIImage type to a Transformable type in your attribute in your database and then save the managedObjectContext
Links to help you:
UIImagePicker Class Reference
Magical Record Docs
CoreData Recipes Sample Project
Hope this help, good luck!
I found my answer:
to save:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString*nomeImmagine = [[NSString alloc] initWithFormat:#"%#", self.fieldName.text];
NSString *pngFilePath = [NSString stringWithFormat:#"%#/%#.png",documentsDirectory, nomeImmagine];
UIImage *image = self.showSelectedImage.image; // imageView is my image from camera
NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(image)];
[data1 writeToFile:pngFilePath atomically:NO];
to load:
-(void) loadImageFromPathInsideView
{
// [self loadImageFromPathInsideView];
Ricetta* contact =[[DataManager sharedClass]dammiTuttaLaRicetta:self.indice];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString*nomeImmagine = [[NSString alloc] initWithFormat:#"%#", contact.nome2];
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [NSString stringWithFormat:#"%#/%#.png",documentsDirectory, nomeImmagine];;
UIImage* image = [UIImage imageWithContentsOfFile:path];
self.image.image = image;
}
a word of advice. storing images as transformable (aka NSImage) type in core data is easy, but leads to overall slow app performance for even a low number (over 20) that range from 50k to 200kb with an average of 100k. even having those files linked via a relationship is slow, considering that one controller is often bound to another.
the above method of storing a local path name as a NSString pointing to Documents folder is heaps better for the overall experience.
that being said, creating a thumbnail image (of around 150x150) can be advantageous to create once and store that as a transient transformable NSImage, rather than loading the biggy and doing an on-the-fly resize a number of times. that performance can be observed easily scrolling up and down in a Table holding 50+ thumbnail images.
Before somebody says something about this topic being duplicated several times, please note that I really don't need loading remote images from the web (SDWebImage github solution), I'm trying to load images dynamically saved on the documents folder, so they are local by the time I want to load them on my tableView having reference to them via a record on a sqlite table in which I saved the image name as it was generated by code.
So after parsing all my sqlite data, in my CellForRowAtIndexPath method at a certain point I have the following lines of code:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
NSString *imageName = [[favorites objectAtIndex:[indexPath row]] objectForKey:#"imagename"];
cell.image.image = [self loadImage: imageName]; // Is a custom cell so cell.image is a UIImageView, and I'm setting its image property
...
}
And my loadImage method looks like:
- (UIImage*)loadImage:(NSString*)imageName {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:#"%#.png", imageName]];
return [UIImage imageWithContentsOfFile:fullPath];
}
Note also that this code actually works but scrolling down the table looks laggy. How can I improve the performance, I mean loading images in the background comes to my mind but the images are already there. Can someone give me a concrete solution on this please?
Just to let you know, I'm working with iOS 5 and ARC.
Any help would be very appreciated.
Firstly decrease the size of image you load.
Secondly try to use GCD to load image in tableView:cellForRowAtIndexPath:.
Ok, it's 3 am atm and I haven't a clue where I put this:
[navigationController.navigationBar setTintColor:[UIColor redColor];
If you would please post the whole .m/.h files that would be great. Also, do I connect anything using segues or outlets? And when you create the .h/.m files do I need UINavigationController or similar selected or just the normal UIViewController? Thanks.
Update: Nevermind I got it, thanks though. Below is the code for others having my issue.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UINavigationBar *bar = [self.navigationController navigationBar];
[bar setTintColor:[UIColor lightGrayColor]];
}
Basically just add on to what's already there.
I feel stupid lol.
You can set that value right after you init your UINavigationController, i.e:
UINavigationController *controller = [[UINabvigationController alloc] initWithRoot...
[controller.navigationBar setTintColor:[UIColor redColor]];
A buddy of mine asked for a quick sample of code for an app skeleton that would use a TableView to call a TabView. I estimated an hour.
After more hours than I want to admit messing around in IB, I gave up and implemented the following code.
Can anyone tell me how to do this in IB? I was careful (I thought) to make all the right connections, but no go. I even had another (working) app where I went through and step-by-step made the same connections. I got errors about "Changing the delegate of a tab bar managed by a tab bar controller is not allowed..." (This when I connected the TabBar's delegate to the File's owner, even though another app was working fine with that setting)
Until I wrote this code, I never got the tabbar view, only the view that came with the view xib... (I tested by putting a label on the view).
Thanks in advance...
UITabBarController *tabBarController = [[[UITabBarController alloc] initWithNibName:nil bundle:nil] autorelease];
NumberOneViewController *numberOneViewController = [[[NumberOneViewController alloc] initWithNibName:#"NumberOneViewController" bundle:nil] autorelease];
NumberTwoViewController *numberTwoViewController = [[[NumberTwoViewController alloc] initWithNibName:#"NumberTwoViewController" bundle:nil] autorelease];
NumberThreeViewController *numberThreeViewController = [[[NumberThreeViewController alloc] initWithNibName:#"NumberThreeViewController" bundle:nil] autorelease];
NumberFourViewController *numberFourViewController = [[[NumberFourViewController alloc] initWithNibName:#"NumberFourViewController" bundle:nil] autorelease];
tabBarController.viewControllers = [NSArray arrayWithObjects:numberOneViewController, numberTwoViewController,
numberThreeViewController, numberFourViewController, nil];
[self.navigationController pushViewController:tabBarController animated:YES];
self.view = tabBarController.view; in the viewDidLoad method of the TabBarController delegate class fixed it...
Ah well, surely someone else will run into the same thing and hopefully this will help them...