[英]iOS - sending URL through mail showing different behavior in simulator and device
A strange behaviour is happening when I am trying to send mail from device. 当我尝试从设备发送邮件时,发生了一种奇怪的行为。
I have used SMTP to send mail from background in my app and I have to send user's current location URL in app. 我已经使用SMTP从后台在我的应用程序中发送邮件,并且必须在应用程序中发送用户的当前位置URL。
Now, when I send it from simulator it works almost fine and i got this url - 现在,当我从模拟器发送它时,它几乎可以正常工作,并且我收到了这个网址-
https://maps.google.com/maps?f=q&q=0.000000,0.000000 https://maps.google.com/maps?f=q&q=0.000000,0.000000
But, when I send it from device it sends the url like this - 但是,当我从设备发送它时,它会发送如下网址:
https://maps.google.com/maps?f=q&q ".719793,75.877068 https://maps.google.com/maps?f=q&q “ .719793,75.877068
The code I used to make url is 我用来制作网址的代码是
-(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]]];
In SMTP mail function, I use this code to make dictionary 在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];
Can anyone suggest me if any change required in code? 有人可以建议我对代码进行任何更改吗?
Why simulator and device are showing different behavior to send this url? 为什么模拟器和设备显示不同的行为来发送此URL?
Use HTML Tag and in mail body enable HTML in iOS 使用HTML标签并在邮件正文中启用iOS中的HTML
[emailDialog setMessageBody:mailBody isHTML:YES]; [emailDialog setMessageBody:mailBody isHTML:YES];
Whenever we have to send URL
thourgh smtp
in objective c, we should always careful about the special character of url. 每当我们必须在目标c中发送URL
thourgh smtp
时,都应始终注意url的特殊字符。
Finally i got the solution of my problem in the encoding process
. 终于我在encoding process
解决了我的问题。
the Encoding in the NSDictionary
object, I changed it from quoted-printable
to 8bit
. NSDictionary
对象中的Encoding,我将其从quoted-printable
更改为8bit
。
Now dictionary
obj would be: 现在dictionary
obj将是:
NSDictionary *plain_text_part = [NSDictionary dictionaryWithObjectsAndKeys:
@"text/plain", kSKPSMTPPartContentTypeKey,
strMessage, kSKPSMTPPartMessageKey,
@"8bit", kSKPSMTPPartContentTransferEncodingKey,
nil];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.