简体   繁体   中英

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.

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

But, when I send it from device it sends the url like this -

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

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?

Use HTML Tag and in mail body enable HTML in iOS

[emailDialog setMessageBody:mailBody isHTML:YES];

Check this page for href tag!

Whenever we have to send URL thourgh smtp in objective c, we should always careful about the special character of url.

Finally i got the solution of my problem in the encoding process .

the Encoding in the NSDictionary object, I changed it from quoted-printable to 8bit .

Now dictionary obj would be:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM