0

「SKPSMTPMessage」を使用してiPhoneでメールを送信しようとしていて、ライブラリを追加しましたが、

私のクラスでは、次のコードを追加しました。

- (IBAction)sendMail:(id)sender 
{
// if there are a connection
if ([theConnection isEqualToString:@"true"]) {
    if ([fromEmail.text isEqualToString:@""] || [toEmail.text isEqualToString:@""]) {
        UIAlertView *warning = [[UIAlertView alloc] initWithTitle:@"تحذير" message:@"لم يتم ادخال جميع المجالات" delegate:self cancelButtonTitle:@"موافق" otherButtonTitles:nil, nil];
        [warning show];
    }else {

        SKPSMTPMessage *test_smtp_message = [[SKPSMTPMessage alloc] init];
        test_smtp_message.fromEmail = fromEmail.text;
        test_smtp_message.toEmail = toEmail.text;
        test_smtp_message.relayHost = @"smtp.gmail.com";
        test_smtp_message.requiresAuth = YES;
        test_smtp_message.login = @"ebookmsg@gmail.com";
        test_smtp_message.pass =  @"myPass";
        test_smtp_message.wantsSecure = YES;

        NSString *subject= @"Suggest a book for you";
        test_smtp_message.subject = [NSString stringWithFormat:@"%@ < %@ > ",fromEmail.text, subject];
        test_smtp_message.delegate = self;

        NSMutableArray *parts_to_send = [NSMutableArray array];


        NSDictionary *plain_text_part = [NSDictionary dictionaryWithObjectsAndKeys:
                                         @"text/plain\r\n\tcharset=UTF-8;\r\n\tformat=flowed", kSKPSMTPPartContentTypeKey,
                                         [messageBody.text stringByAppendingString:@"\n"], kSKPSMTPPartMessageKey,
                                         @"quoted-printable", kSKPSMTPPartContentTransferEncodingKey,
                                         nil];
        [parts_to_send addObject:plain_text_part];

        // to send attachment

        NSString *image_path = [[NSBundle mainBundle] pathForResource:BookCover ofType:@"jpg"];
        NSData *image_data = [NSData dataWithContentsOfFile:image_path];        
        NSDictionary *image_part = [NSDictionary dictionaryWithObjectsAndKeys:
                                    @"inline;\r\n\tfilename=\"image.png\"",kSKPSMTPPartContentDispositionKey,
                                    @"base64",kSKPSMTPPartContentTransferEncodingKey,
                                    @"image/png;\r\n\tname=Success.png;\r\n\tx-unix-mode=0666",kSKPSMTPPartContentTypeKey,
                                    [image_data encodeWrappedBase64ForData],kSKPSMTPPartMessageKey,
                                    nil];


        [parts_to_send addObject:image_part];



        test_smtp_message.parts = parts_to_send;

        Spinner.hidden = NO;
        [Spinner startAnimating];
        ProgressBar.hidden = NO;
        HighestState = 0;

        [test_smtp_message send];

    }

}else {
    UIAlertView *alertNoconnection = [[UIAlertView alloc] initWithTitle:@"تحذير" message:@"لا يوجد شبكة " delegate:self cancelButtonTitle:@"الغاء" otherButtonTitles:nil, nil];
    [alertNoconnection show];
}
}

しかし、送信しようとすると、次の例外が発生します。

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString appendString:]: nil argument'

そしてSKPSMTPMessage.mでこの行を強調表示しました

 [message appendString:[part objectForKey:kSKPSMTPPartMessageKey]];

nil とは何かを正確に理解できません 誰でもこの問題で私を助けることができますか? 前もって感謝します。

4

1 に答える 1

0

私は解決策を見つけました。問題は、image_dataがnullであり、次のように置き換えたためです。

        NSString *image_path = [NSString stringWithFormat:@"%@/%@",[[NSBundle mainBundle] bundlePath],[NSString stringWithFormat:@"%@.jpg",BookCover]];

        NSString *imgLink = [NSString stringWithFormat:@"http://iktab.com/global/modules/bookstore/files/book_cover_photo/%@",BookCover];

        NSString *urlString = [imgLink stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

        NSURL *url = [NSURL URLWithString:urlString];

        NSData* image_data = [NSData dataWithContentsOfURL:url];
于 2012-10-07T12:18:09.657 に答える