Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7717585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:56:17+00:00 2026-06-01T02:56:17+00:00

The app that I’m working on allows the user to pick an image from

  • 0

The app that I’m working on allows the user to pick an image from their camera roll, and display it in a UIImageView. Now, I’m having some issues trying to save the data. I know that I must convert the image to PNG and save the data, but I’m having some issues doing that. I’m very new to file saving and Objective-C in general. Here is the code I’m using:

- (NSString *)dataFilePath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(
                                                         NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    return [documentsDirectory stringByAppendingPathComponent:kFilename9];
}

- (void)applicationDidEnterBackground:(NSNotification *)notification {
    NSMutableArray *array = [[NSMutableArray alloc] init];

    NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image.image)];
    [array addObject:imageData];

    [array writeToFile:[self dataFilePath] atomically:YES];
}
- (void)viewDidLoad
{
    self.imgPicker = [[UIImagePickerController alloc] init];
    self.imgPicker.allowsImageEditing = YES;
    self.imgPicker.delegate = self;
    self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;


    NSString *filePath = [self dataFilePath];
    if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
        NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
        image.image = [array objectAtIndex:0];
    }

    UIApplication *app = [UIApplication sharedApplication];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(applicationDidEnterBackground:)
                                                 name:UIApplicationDidEnterBackgroundNotification
                                               object:app];

    [super viewDidLoad];

}

The program crashed upon simply tapping the tab that this takes place in. The debugger states “‘NSInvalidArgumentException’, reason: ‘-[__NSCFData _isResizable]: unrecognized selector sent to instance 0x16cf50’“. Any help is much appreciated, thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:56:19+00:00Added an answer on June 1, 2026 at 2:56 am

    Okay, first things first, you are getting this error the second you are entering the “tab” that does these operations, yes? So the error should be in your viewDidLoad method. Second, your error calls for a selector error, so find the place where you used @selector.

    Here is your problem that is causing the error:

    [[NSNotificationCenter defaultCenter] addObserver:self
                                                selector:@selector(applicationDidEnterBackground:)
                                                 name:UIApplicationDidEnterBackgroundNotification
                                               object:app];
    

    Notice that the method applicationDidEnterBackground has a parameter (NSNotification*):

    - (void)applicationDidEnterBackground:(NSNotification *)notification {
    

    and yet you are sending it app, which is a UIApplication:

    UIApplication *app = [UIApplication sharedApplication]
    

    This is the only thing that I can see would be giving you this error. Just change it to this and the error should go away:

    - (void)applicationDidEnterBackground:(UIApplication*)application {
    

    BEGIN EDIT:

    As far as saving the image, I don’t know exactly how you are storing the data, but here’s how I would do it.

    1. Use a retained property to store the data of the image.

    ViewController.h

    @interface ViewController
    
    //Add this line
    @property(retain) NSData* imageData;
    
    @end
    

    ViewController.m

    //Remember to include this line somewhere in this file:
    @synthesize imageData;
    

    When you are going to save the file:

    - (void)applicationDidEnterBackground:(UIApplication*)application {
    self.imageData = [NSData dataWithData:UIImagePNGRepresentation(image.image)];
    
    [self.imageData writeToFile:[self dataFilePath] atomically:YES];
    

    }

    This way there is no way that you will lose the data, and you don’t need to use an array. Just make sure to add this line as well in the viewDidUnload method:

    self.imageData = nil;
    

    END EDIT

    Hope that helps you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The app that I'm currently working on is supposed to overlay a square image.
The app that i am working on uses UIWebViews to display vimeo videos. Instead
For a new SaaS app that I'm working on, I want the end user
I have a legacy app that can display crystal reports to the user, using
I`m working on an app that does reading and handling specific URIs from NFC
I have an Android app that looks absolutely horrible if the user sets their
I have an iOS app that gets all the videos from a user through
I'm making an app that allows the user to create files (html) and edit
The App that I'm working on requires to parse a very big Json file
I have a console app that needs to display the state of items, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.