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

  • SEARCH
  • Home
  • 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 5962353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:05:37+00:00 2026-05-22T19:05:37+00:00

I used NSFileManager to read and write in a file. It works fine, but

  • 0

I used NSFileManager to read and write in a file. It works fine, but I cannot view the data written in that file, it works with simulator but doesn’t work in the iPhone.
viewcontroller.h:

#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>

@interface next : UIViewController <MFMailComposeViewControllerDelegate,UITextViewDelegate,UIAlertViewDelegate>{
    IBOutlet UIButton *read;

}
@property(nonatomic,retain)IBOutlet UITextView *txt;
@property (nonatomic, retain) IBOutlet UILabel *message;


-(IBAction)showPicker:(id)sender;
-(void)displayComposerSheet;
-(void)launchMailAppOnDevice;

@end
 viewcontroller.m:
-(void) viewDidLoad {
    self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"mainbg.png"]];
    NSFileManager *filemgr;

    filemgr = [NSFileManager defaultManager];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"help" ofType:@"txt"];
    if ([filemgr fileExistsAtPath:path ] == YES)
        NSLog (@"File exists");
    else
        NSLog (@"File not found");


    NSString *fileName = [[NSBundle mainBundle] pathForResource:@"help" ofType:@"txt"];

    NSString *content1 = [[NSString alloc] initWithContentsOfFile:fileName encoding:NSUTF8StringEncoding error:nil];
    //use simple alert from my library (see previous post for details)
    //NSArray *lines = [content1 componentsSeparatedByString:@"\n"];
    txt.text = content1;
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"file"
                                                    message:content1
                                                   delegate:self
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles: nil];


    [alert show];
    NSLog(@"content1");
    [content1 release];
    [alert release];
    [super viewDidLoad];    


}
//mailing
-(IBAction)showPicker:(id)sender
{
    Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
    if (mailClass != nil)
    {
        // We must always check whether the current device is configured for sending emails
        if ([mailClass canSendMail])
        {
            [self displayComposerSheet];
        }
        else
        {
            [self launchMailAppOnDevice];
        }
    }
    else
    {
        [self launchMailAppOnDevice];
    }
}

-(void)displayComposerSheet 
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    [picker setSubject:@"Hello friends!"];


    // Set up recipients
    NSArray *toRecipients = [NSArray arrayWithObject:@"me11@yahoo.com"]; 
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"me@xyz.com", @"me2@xyz.com", nil]; 
    NSArray *bccRecipients = [NSArray arrayWithObject:@"hii@exe.com"]; 

    [picker setToRecipients:toRecipients];
    [picker setCcRecipients:ccRecipients];  
    [picker setBccRecipients:bccRecipients];

    // Attach an image to the email
    NSString *path = [[NSBundle mainBundle] pathForResource:@"help" ofType:@"txt"];
    NSData *myData = [NSData dataWithContentsOfFile:path];
    [picker addAttachmentData:myData mimeType:@"file/txt" fileName:@"help"];

    // Fill out the email body text
    NSString *emailBody = @"hii how r u !";
    [picker setMessageBody:emailBody isHTML:NO];

    [self presentModalViewController:picker animated:YES];
    [picker release];
}


// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation.
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{   
    message.hidden = NO;
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MFMailComposeResultCancelled:
            message.text = @"Email: Canceled";
            break;
        case MFMailComposeResultSaved:
            message.text = @"Email: Saved";
            break;
        case MFMailComposeResultSent:
            message.text = @"Email: Sent";
            break;
        case MFMailComposeResultFailed:
            message.text = @"Email: Failed";
            break;
        default:
            message.text = @"Email: Not Sent";
            break;
    }
    [self dismissModalViewControllerAnimated:YES];
}


#pragma mark -
#pragma mark Workaround

// Launches the Mail application on the device.
-(void)launchMailAppOnDevice
{
    NSString *recipients = @"mailto:friend@abc.com?cc=me@xyz.com,@me2@xyz.com&subject=Hello !";
    NSString *body = @"&body=hello how r u !";

    NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
    email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}
  • 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-05-22T19:05:38+00:00Added an answer on May 22, 2026 at 7:05 pm

    Can you use the real-time debugger ?
    1) set break points to check the variables/path
    2) create some try-catch blocks to see if there’s an ‘unhandled’ exception somewhere

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

Sidebar

Related Questions

I am simple exporting my data into CSV file. But when I click on
I used the codes below to check if a file exists bool b=[[NSFileManager defaultManager]
Actually i want to read and write the file using filemanager in Quicklook plugin.
I am building application that required some data from iPhone's Call log(read only). The
Anybody used Neural Network approaches for clustering data? Particularly ART Neural Network (Adaptive Resonance
I used the phonegap website to create an IPA file. Now I want to
I used Session[EmpName] = Convert.ToString(Request.QueryString[1]); lblEmployeeName.Text = Session[EmpName].ToString; to show the data in label
i used this code: List<string> lists=new List<string>(apple,orange,banana,apple,mang0,orange); string names; names=lists.Distinct() is that correct?
I used as described in the Apple Docs NSMetadataQuery to search my iCloud file.
I'm working on an app that writes data out to a .plist from a

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.