1

I can send a location by embedding the person's location in a VCF through an email by including it as an attachment. I do not know how to do the same through SMS. Is it still sending a VCF format, or is it some other method? I see the default SMS can do it and it just says "Dropped Pin" and goes to what looks like a Contact Information screen if you try to SMS a dropped pin from the map application. I'm basically trying to do something similar through SMS, but don't know how to format the data.

I found this post that is similar: how to programmatically send business card messages to mobile phone via internet

I do not know what it means though to put in SMS format. Any thoughts? Thanks!

Community
  • 1
  • 1
Crystal
  • 28,460
  • 62
  • 219
  • 393

3 Answers3

5

Actually it is MMS (with attached vcf), and there is no way to send MMS from application. Sorry :(

Deniz Mert Edincik
  • 4,336
  • 22
  • 24
1

You may paste the contents of the vcf file into the sms... This is how the old phones solve this problem. Deniz is right, there is no way to send MMS from the application, so, you should use the old way to send a vcf file.


So the possibilities (I know only one possibility).
Read the contents of file to a string with this method:

- (id)initWithContentsOfFile:(NSString *)path usedEncoding:(NSStringEncoding *)enc error:(NSError **)error

Then you can set the body of an MFMessageComposeViewController.
I hop this is clear.

Infinite Possibilities
  • 7,415
  • 13
  • 55
  • 118
  • Can you expand on how that works? I haven't been able to find any code snippets or discussion on how you send an attachment as an MMS either? Thanks. – Crystal Sep 18 '11 at 20:09
  • You can't send MMS from the application, but tomorrow morning (it's night here), I will tell you how can you send the contents of a vcf file. – Infinite Possibilities Sep 18 '11 at 21:29
  • Possibilites Well it didn't work to put the info I needed into the SMS, but I appreciate the help. Gave you the bounty for your help. Thanks. – Crystal Sep 20 '11 at 03:19
  • Let me know, why didn't you solve the problem? I think we are here to help you, not for the bounty... :D What was the problem, that prevented you to from success? If I can add you any further help, please let me know. – Infinite Possibilities Sep 20 '11 at 06:08
  • It basically shows the VCard string I created in the text message. When you send a contact via the iPhone via SMS, you see some Icon that you can click on that brings to the contacts page where you can add them to existing contacts, share contact, add new contact, etc. InitWithContentsOfFile just prints the VCard text :-\. – Crystal Sep 20 '11 at 22:57
  • Aa, now I understand what do you mean. I try to check how is this done, but I think, this is Apple only at the moment, but I am not sure. – Infinite Possibilities Sep 21 '11 at 06:10
0

Use Below code to send vCard as an attachment in a message

if([MFMessageComposeViewController canSendText])
{
    MFMessageComposeViewController *msgController = [[MFMessageComposeViewController alloc] init] ;
    msgController.body = bodyString;
    if (phoneNumberArray != nil) {
        msgController.recipients = phoneNumberArray;
    }

    msgController.messageComposeDelegate = self;
    if([MFMessageComposeViewController canSendAttachments] && [MFMessageComposeViewController isSupportedAttachmentUTI:(NSString *)kUTTypeVCard]) {
        NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory,     NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];

        NSString * contactCardPath = [documentsDirectory stringByAppendingFormat:@"/%@",KVCardFileName]; //Path of vCard saved in your document directory
        if([[NSFileManager defaultManager]fileExistsAtPath:contactCardPath]) {
            NSData *vCardContact = [[NSFileManager defaultManager] contentsAtPath:contactCardPath];
            [msgController addAttachmentData:vCardContact typeIdentifier:(NSString *)kUTTypeVCard filename:KVCardFileName];
        }
    }


    [self presentViewController:msgController animated:YES completion:^{
        [SVProgressHUD dismiss];
    }];
}
parth
  • 853
  • 11
  • 18