2017-07-19 89 views
0

我已經創建了在whatsapp上共享我的應用程序的代碼。問題是當共享鏈接從ios發送到android手機時,url鏈接和文本都以純文本格式顯示在android手機的whatsapp聊天框中,沒有突出顯示鏈接和網址。 這可以解決嗎?怎麼樣?iOS:使用目標的應用程序共享URL C

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"]; 
     } 

回答

0

我使用此代碼在whatsapp上共享,它工作得很好。純文本問題發生在Android OS 5.0及更早的版本中。

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; 
    } 
相關問題