簡體   English   中英

iOS-通過郵件發送URL,顯示模擬器和設備中的不同行為

[英]iOS - sending URL through mail showing different behavior in simulator and device

當我嘗試從設備發送郵件時,發生了一種奇怪的行為。

我已經使用SMTP從后台在我的應用程序中發送郵件,並且必須在應用程序中發送用戶的當前位置URL。

現在,當我從模擬器發送它時,它幾乎可以正常工作,並且我收到了這個網址-

https://maps.google.com/maps?f=q&q=0.000000,0.000000

但是,當我從設備發送它時,它會發送如下網址:

https://maps.google.com/maps?f=q&q “ .719793,75.877068

我用來制作網址的代碼是

-(NSString*)LocationLinkTosentInMail
{
    CLLocationCoordinate2D coordinate = [self getLocation];
    NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
    NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];

    NSLog(@"*dLatitude : %@", latitude);
    NSLog(@"*dLongitude : %@",longitude);


    NSString *currentLocationURL = [NSString stringWithFormat:@"https://maps.google.com/maps?f=q&q=%@,%@",latitude,longitude];

    return currentLocationURL;

}


 NSURL *locationURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@",[self LocationLinkTosentInMail]]];

在SMTP郵件功能中,我使用此代碼制作字典

NSDictionary *plain_text_part = [NSDictionary dictionaryWithObjectsAndKeys:
                                         @"text/plain\r\n\tcharset=UTF-8;\r\n\tformat=flowed", kSKPSMTPPartContentTypeKey,
                                         [NSString stringWithFormat:@"My Location is: %@",locationURL], kSKPSMTPPartMessageKey,
        @"quoted-printable", kSKPSMTPPartContentTransferEncodingKey,
        nil];

有人可以建議我對代碼進行任何更改嗎?

為什么模擬器和設備顯示不同的行為來發送此URL?

使用HTML標簽並在郵件正文中啟用iOS中的HTML

[emailDialog setMessageBody:mailBody isHTML:YES];

檢查此頁面的href標簽!

每當我們必須在目標c中發送URL thourgh smtp時,都應始終注意url的特殊字符。

終於我在encoding process解決了我的問題。

NSDictionary對象中的Encoding,我將其從quoted-printable更改為8bit

現在dictionary obj將是:

 NSDictionary *plain_text_part = [NSDictionary dictionaryWithObjectsAndKeys:
                                 @"text/plain", kSKPSMTPPartContentTypeKey,
                            strMessage, kSKPSMTPPartMessageKey,
                                 @"8bit", kSKPSMTPPartContentTransferEncodingKey,
                                 nil];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM