我正在尝试从iOS上的Ionic应用程序发送彩信,但我只能收到包含正文或图像附件的消息,而不能同时包含两者。
我正在使用cordova-sms插件,特别是WIP MMS分支。
这是Sms.m中的代码,用于处理消息并通过MFMessageComposeViewController启动Message应用程序:
- (void)send:(CDVInvokedUrlCommand*)command {
self.callbackID = command.callbackId;
[self.commandDelegate runInBackground:^{
// test SMS availability
if(![self isSMSAvailable]) {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"SMS_NOT_AVAILABLE"];
return [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackID];
}
// retrieve the options dictionnary
NSDictionary* options = [command.arguments objectAtIndex:2];
// parse the body parameter
NSString *body = [self parseBody:[command.arguments objectAtIndex:1] replaceLineBreaks:[[options objectForKey:@"replaceLineBreaks"] boolValue]];
// parse the recipients parameter
NSMutableArray *recipients = [self parseRecipients:[command.arguments objectAtIndex:0]];
// parse the attachments
NSArray *attachments = [options objectForKey:@"attachments"];
// initialize the composer
MFMessageComposeViewController *composeViewController = [[MFMessageComposeViewController alloc] init];
composeViewController.messageComposeDelegate = self;
// add recipients
[composeViewController setRecipients:recipients];
// append the body to the composer
if ((id)body != [NSNull null]) {
[composeViewController setBody:body];
}
// append attachments
if (attachments != nil && [attachments count] > 0) {
if(![self areAttachmentsAvailable]) {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"MMS_NOT_AVAILABLE"];
return [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackID];
}
for (id attachment in attachments) {
NSURL *file = [self getFile:attachment];
if (file != nil) {
[composeViewController addAttachmentURL:file withAlternateFilename:nil];
}
}
}
// fire the composer
[self.viewController presentViewController:composeViewController animated:YES completion:nil];
}];
}
同样,如果我通过附件选项添加图像文件,则消息将仅包含所述图像,如果不添加图像文件,则消息将仅包含文本正文。
如何使消息同时包含两者?
对不起,如果我遗漏了任何重要信息,这是我关于SO的第一个问题。请让我知道我是否可以添加任何内容以简化回答。预先谢谢你!