0

I am trying to embed a link in a twee sent out from iPhone. The URL ends with a closing parentheses. That parentheses gets dropped and causes the t.co link to fail. I have tried encoding, tagging with href. Nothing seems to bring that closing parentheses into the resulting URL. See what I tried last, it failed for having too many characters. Why didn't it get shortened?:

    if (tweetsEnabled && twitToSendTo != nil) {
        // Build the string
        NSString *mapURL = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@,%@+(%@)",newLogEvent.lattitude,newLogEvent.longitude,eventString];
        NSString *encodedURL = [mapURL encodeString:NSUTF8StringEncoding];
        NSString *tweetString = [NSString stringWithFormat:@"%@\n<a href>=\"%@\"></a>",note,encodedURL];
        NSLog(@"%@",tweetString);
        // Send it
        [self performSelectorOnMainThread:@selector(postToTwitterWithString:) withObject:tweetString waitUntilDone:NO];
    } 

In its simplest form,without encoding, without the tags and without the +(%@), the link works. It displays as a t.co shortened link and brings up the webpage as intended. But I need the string in the parentheses to give text to the label and it seems it should be very easy to get that in.

Here is the output of the NSLog:

2012-08-14 09:57:43:551 app[2683:34071] -[logger insertLogEvent:withLocation:isArrival:] [Line 641] Arrival logged for Home
<a href>="http%3A%2F%2Fmaps.google.com%2Fmaps%3Fq%3D26.17071170827948%2C-80.16628238379971%2B%28Arrival%29"></a>
Dean Davids
  • 4,174
  • 2
  • 30
  • 44

1 Answers1

0

This worked:

// Build the string
        NSString *mapURL = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@,%@+%%28%@%%29",newLogEvent.lattitude,newLogEvent.longitude,eventString];
        NSString *tweetString = [NSString stringWithFormat:@"%@\n%@",note,mapURL];

I am not now encoding the entire string but only the parenthesis. This handy post, How to add percent sign to NSString , is where I found the correct way to get the percent signs in for the encoding.

Community
  • 1
  • 1
Dean Davids
  • 4,174
  • 2
  • 30
  • 44