-
Notifications
You must be signed in to change notification settings - Fork 957
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97fb130
commit 1faeac7
Showing
5 changed files
with
110 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// FacebookShare.h | ||
// RNShare | ||
// | ||
// Created by Diseño Uno BBCL on 23-07-16. | ||
// Copyright © 2016 Facebook. All rights reserved. | ||
// | ||
|
||
|
||
#import <Social/Social.h> | ||
#import <UIKit/UIKit.h> | ||
#import "RCTConvert.h" | ||
#import "RCTBridge.h" | ||
#import "RCTUIManager.h" | ||
#import "RCTLog.h" | ||
#import "RCTUtils.h" | ||
#import <MessageUI/MessageUI.h> | ||
@interface EmailShare : NSObject <MFMailComposeViewControllerDelegate> | ||
|
||
- (void *) shareSingle:(NSDictionary *)options failureCallback:(RCTResponseErrorBlock)failureCallback successCallback:(RCTResponseSenderBlock)successCallback; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// FacebookShare.m | ||
// RNShare | ||
// | ||
// Created by Diseño Uno BBCL on 23-07-16. | ||
// Copyright © 2016 Facebook. All rights reserved. | ||
// | ||
|
||
#import "EmailShare.h" | ||
|
||
|
||
@implementation EmailShare | ||
- (void)shareSingle:(NSDictionary *)options | ||
failureCallback:(RCTResponseErrorBlock)failureCallback | ||
successCallback:(RCTResponseSenderBlock)successCallback { | ||
|
||
NSLog(@"Try open view"); | ||
|
||
if ([options objectForKey:@"message"] && [options objectForKey:@"message"] != [NSNull null]) { | ||
NSString *text = [RCTConvert NSString:options[@"message"]]; | ||
|
||
if ([MFMailComposeViewController canSendMail]) { | ||
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init]; | ||
[mailController setMailComposeDelegate:self]; | ||
if ([options objectForKey:@"subject"] && [options objectForKey:@"subject"] != [NSNull null]) { | ||
[mailController setSubject: options[@"subject"]]; | ||
} | ||
if ([options objectForKey:@"message"] && [options objectForKey:@"message"] != [NSNull null]) { | ||
[mailController setMessageBody:options[@"message"] isHTML:NO]; | ||
} | ||
|
||
NSURL *URL = [RCTConvert NSURL:options[@"url"]]; | ||
if (URL) { | ||
if (URL.fileURL || [URL.scheme.lowercaseString isEqualToString:@"data"]) { | ||
NSError *error; | ||
NSData *data = [NSData dataWithContentsOfURL:URL | ||
options:(NSDataReadingOptions)0 | ||
error:&error]; | ||
if (!data) { | ||
failureCallback(error); | ||
return; | ||
} | ||
// ONLY images attach | ||
time_t unixTime = (time_t) [[NSDate date] timeIntervalSince1970]; | ||
NSString *timestamp=[NSString stringWithFormat:@"%ld",unixTime]; | ||
[mailController addAttachmentData:data mimeType: @"image/jpg" fileName: [timestamp stringByAppendingString: @".jpg"] ]; | ||
|
||
} else { | ||
[mailController setMessageBody:[options[@"message"] stringByAppendingString: [@" " stringByAppendingString: options[@"url"]]] isHTML:NO]; | ||
} | ||
} | ||
|
||
UIViewController *root = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; | ||
|
||
|
||
[root presentViewController:mailController animated:YES completion:nil]; | ||
|
||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { | ||
NSLog(@"finish email"); | ||
[controller becomeFirstResponder]; | ||
[controller dismissViewControllerAnimated:YES completion:nil]; | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters