Send location information or vCard through SMS on iPhone
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 fo开发者_开发知识库rmat. Any thoughts? Thanks!
Actually it is MMS (with attached vcf), and there is no way to send MMS from application. Sorry :(
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.
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];
}];
}
精彩评论