【问题标题】:Ios Mailcore canopenurlios Mailcore canopenurl
【发布时间】:2016-06-18 02:37:24
【问题描述】:

canOpenURL:URL 失败:“googlemail:” - 错误:“此应用不允许查询方案 googlemail” 这是我在完成所有工作后遇到的错误。还在项目的 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
}

【问题讨论】:

    标签: ios iphone mailcore2 mailcore


    【解决方案1】:

    您的库是在没有位码的情况下编译的,但位码选项是 在您的项目设置中启用。对启用 Bitcode 说不 目标构建设置和库构建设置以删除 警告。

    对于那些想知道是否需要启用位码的人:

    注意:对于 iOS 应用程序,位码是默认设置,但可选。如果您提供位码,则应用程序包中的所有应用程序和框架都需要包含位码。对于 watchOS 应用,需要位码。

    参考SO

    【讨论】:

    • 那么你的错误是什么......在同样的问题上对我来说效果很好
    • 总是出现这个错误 canOpenURL: failed for URL: "googlemail:" - error: "This app is not allowed to query for scheme googlemail"
    • 然后发送电子邮件时出错:Error Domain=MCOErrorDomain Code=1“无法建立与服务器的稳定连接。” UserInfo={NSLocalizedDescription=无法建立与服务器的稳定连接。} '
    【解决方案2】:

    您可以使用此代码确定是否安装了任何类型的应用程序(只需将 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
            } 
    

    【讨论】:

    • 我在模拟器上运行它。意味着我需要模拟器上的 googlemail?
    • 已下载,但即使在设备上也出现同样的错误
    • @faizan-ullah 欢迎 :)
    猜你喜欢
    • 2012-02-27
    • 2017-02-05
    • 2012-08-05
    • 1970-01-01
    • 2016-06-22
    • 2015-08-24
    • 1970-01-01
    • 2013-01-18
    • 2012-06-26
    相关资源
    最近更新 更多