2014-03-27 109 views
1

我是新來的flex移動應用程序開發,我想通過whatsapp分享一個文本。這是一些代碼,但它不工作。通過whatsapp發送文本無法正常工作

navigateToURL(new URLRequest("whatsapp://send?text=Hello how r u???") 

你能幫我嗎。 在此先感謝。

+0

在這裏找到的解決方案? – Yossi

+0

沒有。通過郵件聯繫WhatsApp團隊後,我才知道這不是可能的,因爲whatapp沒有提供任何第三方API。如果你有任何解決方案,請在這裏評論@Yossi –

+0

其實我得到了。請看下面的答案。 – Yossi

回答

0

試試看看這個代碼。應該完美地工作。

-(void)whatsapp{ 
     NSString *massage = [self stringByEncodingString:@"Your massage"]; 
     NSString *urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@",massage]; 
     NSURL *whatsappURL = [NSURL URLWithString:urlWhats]; 
     if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) { 
      [[UIApplication sharedApplication] openURL: whatsappURL]; 
     } else { 
      UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has to have WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
      [alert show]; 
     } 
} 

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