canOpenURL:失败的网址:“谷歌邮件:”-错误:“这个应用程序是不允许查询方案谷歌邮件”,这是错误的我得到了所有的工作。还将字符串添加到项目的info.plist中。
//Convert the image into data
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(self.emailimage)];
//Create a base64 string representation of the data using NSData+Base64
NSString *base64String = [imageData base64EncodedString];
//userdefaults
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// getting an NSString
NSString *userName = [prefs stringForKey:@"username"];
NSString *password = [prefs stringForKey:@"password"];
//email operation strat
MCOSMTPSession *smtpSession = [[MCOSMTPSession alloc] init];
smtpSession.hostname =@"smtp.gmail.com";
//
smtpSession.port = 465;
smtpSession.username =userName;
smtpSession.password =password;
smtpSession.authType = MCOAuthTypeSASLPlain;
smtpSession.connectionType =MCOConnectionTypeStartTLS;
MCOMessageBuilder *builder = [[MCOMessageBuilder alloc] init];
MCOAddress *from1 = [MCOAddress addressWithDisplayName:@""
mailbox:userName];
MCOAddress *to1 = [MCOAddress addressWithDisplayName:nil
mailbox:self.to.text];
[[builder header] setFrom:from1];
[[builder header] setTo:@[to1]];
[[builder header] setSubject:self.subject.text];
NSDate *now = [NSDate date];
double seconds1 = [now timeIntervalSince1970];
NSNumber *seconds = [NSNumber numberWithInteger:seconds1];
NSLog(@"id is=======================%@",seconds);
AppDelegate *tokenD = [[UIApplication sharedApplication]delegate];
NSLog(@"token in Composeviewcontroller %@",tokenD.Dtoken);
NSString *htmlbody1;
[builder setHTMLBody:htmlbody1];
MCOAttachment *attachment = [MCOAttachment attachmentWithContentsOfFile:self.filename];
[builder addAttachment:attachment];
NSData * rfc822Data = [builder data];
MCOSMTPSendOperation *sendOperation =
[smtpSession sendOperationWithData:rfc822Data];
[sendOperation start:^(NSError *error) {
if(error) {
NSLog(@"Error sending email: %@", error);
}
else {
NSLog(@"Successfully sent email!");
}
}];
//coredata
NSManagedObjectContext *context = [self managedObjectContext];
if (self.emailInfo) {
[self.emailInfo setValue:self.to.text forKey:@"email_to"];
[self.emailInfo setValue:self.subject.text forKey:@"email_sub"];
[self.emailInfo setValue:self.htmlbody.text forKey:@"email_body"];
[self.emailInfo setValue:seconds forKey:@"email_id"];
[self.emailInfo setValue:@"sent" forKey:@"status"];
[self.emailInfo setValue:seconds forKey:@"email_id"];
} else {
NSManagedObject *newEmail = [NSEntityDescription insertNewObjectForEntityForName:@"EmailInfo" inManagedObjectContext:context];
[newEmail setValue:self.to.text forKey:@"email_to"];
[newEmail setValue:self.subject.text forKey:@"email_sub"];
[newEmail setValue:self.htmlbody.text forKey:@"email_body"];
[newEmail setValue:seconds forKey:@"email_id"];
[newEmail setValue:@"sent" forKey:@"status"];
[newEmail setValue:seconds forKey:@"email_time"];
}
NSError *error = nil;
if (![context save:&error]) {
NSLog(@"%@ %@", error, [error localizedDescription]);
}
[self.navigationController popViewControllerAnimated:YES];
// Fetching
// Do any additional setup after loading the view.
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gamecenter:/me/account"]];
NSString *gmailurl = [NSString stringWithFormat:@"googlemail:"];
NSURL *openURL = [NSURL URLWithString:gmailurl];
// googlegmail:///co?to={email}&subject={subject}&body={body}
if ([[UIApplication sharedApplication] canOpenURL:openURL]) {
[[UIApplication sharedApplication] openURL:openURL];// launch it
}发布于 2016-03-04 11:49:17
您可以使用以下代码确定是否安装了任何类型的应用程序(只需将customURL替换为其他应用程序即可):
NSString *customURL = @"googlegmail://";
if ([[UIApplication sharedApplication]
canOpenURL:[NSURL URLWithString:customURL]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:customURL]];
}
else
{
//not installed, show popup for a user or an error
} 发布于 2016-03-04 11:23:44
您的库是在没有bitcode的情况下编译的,但是在您的项目设置中启用了bitcode选项。说“否”可以在目标生成设置中启用Bitcode,而“库生成设置”可以删除警告。 对于那些想知道是否需要启用bitcode的人:
注意:对于iOS应用程序,bitcode是默认的,但是是可选的。如果您提供bitcode,那么应用程序包中的所有应用程序和框架都需要包含bitcode。对于watchOS应用程序,比特代码是必需的。
参考SO
https://stackoverflow.com/questions/35794713
复制相似问题