简体   繁体   中英

iOS: App Share URL using objective C

I have created the code to share my app on whatsapp. The problem is when the share link is sent from ios to an android phone, the url link and text all are displayed in plain text format in android phone's whatsapp chat box, without highlighted link and url. Can this be fixed? How?

NSString *urlString = [NSString stringWithFormat:@"%@", APP_SHARE_URL];
        NSString *initialText1 = [NSString stringWithFormat:@"Hey I am using App: %@\n%@",urlString, profileModel.name];
        NSCharacterSet *set = [NSCharacterSet URLHostAllowedCharacterSet];
        NSString *whatsappString = [NSString stringWithFormat:@"%@", [[NSString stringWithFormat:@"%@", initialText1] stringByAddingPercentEncodingWithAllowedCharacters:set]];
        NSURL *whatsappURL = [NSURL URLWithString:[NSString stringWithFormat:@"whatsapp://send?text=%@", whatsappString]];

        if ([[UIApplication sharedApplication] canOpenURL:whatsappURL]) {
            [[UIApplication sharedApplication] openURL:whatsappURL];
        }
        else {
            [self showMessage:@"Unable to open WhatsApp"];
        }

I am using this code for sharing on whatsapp and it works absolutely fine. Plain text issue occurs in Android OS 5.0 and earlier.

NSString *textToShare = [self getEncodedString:text];
NSString *urlStr = @"whatsapp://send?text=";    
urlStr = [NSString stringWithFormat:@"%@%@",urlStr,textToShare];
NSURL *url = [NSURL URLWithString:urlStr];
[[UIApplication sharedApplication] openURL:url]

- (NSString*)getEncodedString:(NSString*)string {
        NSString * encodedString = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(
                                                                                                         NULL,
                                                                                                         (CFStringRef)string,
                                                                                                         NULL,
                                                                                                         (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ",
                                                                                                         kCFStringEncodingUTF8 ));
        return encodedString;
    }

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