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?