2016-03-04 51 views
0

canOpenURL:URL失敗:「googlemail:」 - 錯誤:「該應用程序不允許查詢Googlemail方案」 這是所有工作後的錯誤即時錯誤..還向信息添加了字符串。項目的plist。Ios Mailcore canopenurl

//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 [email protected]"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 
} 

回答

0

可確定的,如果使用此代碼安裝在任何類型的應用程序(只需更換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 
     } 
+0

即時通訊模擬器上運行它。意味着我需要模擬器上的googlemail? –

+0

@Faizan是的,你需要谷歌郵件... –

+0

下載,但仍然得到同樣的錯誤,即使在設備上也 –

0

Your library was compiled without bitcode, but the bitcode option is enabled in your project settings. Say NO to Enable Bitcode in your target Build Settings and the Library Build Settings to remove the warnings.

For those wondering if enabling bitcode is required:

注:對於iOS應用,位碼是默認的,但可選的。如果您提供位碼,應用程序包中的所有應用程序和框架都需要包含位碼。對於watchOS應用程序,位碼是必需的。

參考SO

+0

禁用位碼 –

+0

我不是後,仍然得到同樣的錯誤得到與位碼有關的任何錯誤。 –

+0

所以最新你的錯誤..它在我的同樣的問題上工作得很好 – viratpuar

相關問題