繁体   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