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>
4

1 に答える 1

0

これはうまくいきました:

// 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];

文字列全体をエンコードするのではなく、括弧のみをエンコードしています。この便利な投稿、パーセント記号を NSString に追加する方法は、エンコーディング用にパーセント記号を取得する正しい方法を見つけた場所です。

于 2012-08-14T15:11:08.180 に答える