0

I am using sharekit plugin for phonegap in my application. This plugin allows me to set the body and subject of the email . However it does not have an option to set the 'to' /recipient field. I do not know Objective C. Can you please help me achieve this functionality by giving me a guide on what i need to add/change in which files.

Here is a link to the plugin i am using

https://github.com/phonegap/phonegap-plugins/tree/master/iOS/ShareKitPlugin

Thanks

vijar
  • 733
  • 4
  • 14
  • 23

1 Answers1

0

There is a response in this question :

https://stackoverflow.com/a/7648354/1272540

So in ShareKitPlugin.m add in :

- (void)shareToMail:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
    [SHK setRootViewController:self.viewController];

    SHKItem *item;

    NSString *subject = [arguments objectAtIndex:1];
    NSString *body = [arguments objectAtIndex:2];

    item = [SHKItem text:body];
    item.title = subject;

    // **start of added code
    NSString *recipient = [arguments objectAtIndex:3]; 
    [item setCustomValue:recipient forKey:@"toField"];
    // **end of added code

    [SHKMail shareItem:item];

}

and this in SHKMail.m :

[mailController setSubject:self.item.title];
[mailController setMessageBody:body isHTML:YES];

// **start of added code
NSString *recipient = [self.item customValueForKey:@"toField"];
NSLog(@"recipient: %@", recipient);
if (recipient != nil) {
    NSArray *recipients = [[NSArray alloc] initWithObjects:recipient, nil];
    [mailController setToRecipients:recipients];
    [recipient release];
    [recipients release];
}
// **end of added code

[[SHK currentHelper] showViewController:mailController];

and in ShareKitPlugin.js :

ShareKitPlugin.prototype.shareToMail = function( subject, message , recipient)
{
    if(typeof recipient === undefined){
    recipient = '';
    }

    cordova.exec(null, null, "ShareKitPlugin", "shareToMail", [subject, message , recipient] );

};

this code come from gitHub : https://github.com/ideashower/ShareKit/issues/281

Community
  • 1
  • 1
Yann86
  • 1,018
  • 10
  • 16
  • I am not able to compile as i am getting an error on the first line of the new code in shkmail.m i.e 'NSString *recipient = [item customValueForKey:@"toField"];' . The error i am getting is "use of undeclared identifier 'item' " – vijar May 23 '13 at 14:47
  • I tried that . I was able to get to composer to load with a email address in the to field. However if i send or exit out of the mail the app gets paused and and jumps to xcode . Also the places where i am not putting a recipient the app pauses and in the console it says terminating app due to uncaught exception . And i see something like 'unrecognised selector sent to instance' . I dont know objective C so i dunno why this is happening – vijar May 23 '13 at 20:14
  • This is what i see in the console when i try to compose a email without a recipient Pcg[79795:c07] recipient: 2013-05-23 16:10:24.912 pcg[79795:c07] -[NSNull mf_isLegalCommentedEmailAddress]: unrecognized selector sent to instance 0x909678 2013-05-23 16:10:24.912 pcg[79795:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull mf_isLegalCommentedEmailAddress]: unrecognized selector sent to instance 0x909678' *** First throw call stack: (0x7d8012 0x2fc6e7e...etc) libc++abi.dylib: terminate called throwing an exception (lldb) – vijar May 23 '13 at 20:16
  • ok I have edited the code inside ShareKitPlugin.js to always send a string to shareToMail method – Yann86 May 23 '13 at 20:24
  • When i send an email with a recipient which opens perfectly it pauses and this line is highlightes in thread 1 objc_msgsend `0x2fd809b: movl 8(%edx), %edi` and a green arrow says "EXC_BAD_ACCESS(code=1, address=0x20c4c6b2)" – vijar May 23 '13 at 20:25
  • for the second error i don't know where it occurs do you try in the simulator? EXC_BAD_ACCESS means you try to acces to a released object.I can't help you more without code – Yann86 May 23 '13 at 20:30
  • ok thanks. Do u think adding self.item instead of item has something to do with it? . I know u cant say much without the code but still – vijar May 23 '13 at 20:48
  • I think there is a problem with the MailComposerDelegate he is called each times went you tap cancel or send button. but i have never use share kit so i can't tell you more. If you want send me a exemple project i can take a look – Yann86 May 23 '13 at 20:53