Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29917

Sending an email with a file attachment in objective c

$
0
0

I have tried this:

-(void)sendEmail:(NSString*)file_path{
    NSURL* url = [[NSURL alloc] initFileURLWithPath:file_path];
    NSArray* items = [NSArray arrayWithObject:url];
    NSSharingService *service = [NSSharingService sharingServiceNamed:NSSharingServiceNameComposeEmail];
    service.recipients=@[@"max@bar.com"];
    service.subject= [NSString stringWithFormat:@"%@",NSLocalizedString(@"Error fetching credentials",nil)];
    service.delegate = self;
    NSLog(@"canPerform %@", [service canPerformWithItems:items] ? @"YES" : @"NO");
    [service performWithItems:items];
}

where file_path is like: /Users/username/Desktop/test.txt.

I am getting the error:

Could not instantiate class NSURL. Error: Error Domain=NSCocoaErrorDomain Code=4864 "value for key 'root' was of unexpected class 'NSNull'. Allowed classes are '{(
    NSURL
)}'." UserInfo={NSDebugDescription=value for key 'root' was of unexpected class 'NSNull'. Allowed classes are '{(
    NSURL
)}'.}

What is going on?


Viewing all articles
Browse latest Browse all 29917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>