代码之家  ›  专栏  ›  技术社区  ›  wesley

如果我们在长时间间隔后使用MSGraphSDK,则在iOS中无法使用发送邮件功能

  •  0
  • wesley  · 技术社区  · 5 年前

    我们不允许使用本机邮件功能发送电子邮件。

    因此,我们的原生iPad应用程序集成了MSGraph SDK,可与附件一起发送邮件。MSGraphSDK用于通过获取身份验证凭据来验证工作用户。

    NSArray *scopes = [kScopes componentsSeparatedByString:@","];
    [self.authProvider connectToGraphWithClientId:kClientId scopes:scopes completion:^(NSError *error) {
                        if (!error) {
                            NSLog(@"Authentication successful.");
                            [self sendMailWithAttachments];
                        }
    }];
    

    从下一次开始,它将直接发送邮件,而无需询问工作证明。

    [MSGraphClient setAuthenticationProvider:self.authProvider.authProvider];
    self.graphClient = [MSGraphClient client];
    
    MSGraphMessage *message = [self getSampleMessage];
    MSGraphUserSendMailRequestBuilder *requestBuilder = [[self.graphClient me]sendMailWithMessage:message saveToSentItems:true];
    MSGraphUserSendMailRequest *mailRequest = [requestBuilder request];
    [mailRequest executeWithCompletion:^(NSDictionary *response, NSError *error) {
            if(!error){
    }
    }];
    

    MSGraph SDK用于在用户未通过身份验证或用户身份验证未成功时自动引导经过身份验证的页面。

    现在的问题是,用户正在尝试对自己进行身份验证,并在最初几次成功地发送邮件。一个多月后,他们试图用这个应用发送邮件。不幸的是,它没有任何反应。

    0 回复  |  直到 5 年前
        1
  •  -1
  •   Dhananjay Patel    5 年前

    请尝试以下代码:

    NSString *titleEmail =  @"Your title";
    NSString *msgBody = @"PFA";
    NSArray *toRecipents = [NSArray arrayWithObject:@"xyz@gmail.com"];
    
    NSMutableData *pdfData = [NSMutableData data];
    UIGraphicsBeginPDFContextToData(pdfData, self.view.bounds, nil);
    UIGraphicsBeginPDFPage();
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIGraphicsEndPDFContext();
    
    MFMailComposeViewController *mailComposeVC = [[MFMailComposeViewController alloc] init];
    mailComposeVC.mailComposeDelegate = self;
    [mailComposeVC setSubject:titleEmail];
    [mailComposeVC setMessageBody:msgBody isHTML:NO];
    [mailComposeVC addAttachmentData:pdfData mimeType:@"application/pdf" fileName:@"MY.pdf"];
    [mailComposeVC setToRecipients:toRecipents];
    
    [self presentViewController:mailComposeVC animated:YES completion:NULL];