2015-10-02 1 views
0

Я пытаюсь разделить текст + url thru WhatsApp, но не получаю ничего, заполненного текстовым полем WhatsApp.Не удается передать url со строкой в ​​whatsapp

Я попытался следующий код:

NSString *urlString = [NSString stringWithFormat:@"http://www.mouthshut.com/contest?ref=%@&inv_via=whatsapp&act=reg", UserName]; 

//NSURL *url = [NSURL URLWithString:urlString]; 
//urlString = [urlString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

NSString * urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=Writing a review is better than whatsapp. Win cash prizes daily on MouthShut.com \n Join Now %@", urlString]; 

NSURL * whatsappURL = [NSURL URLWithString:[urlWhats stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 

if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) { 
    [[UIApplication sharedApplication] openURL: whatsappURL]; 
} else { 
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Alert!" message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alert show]; 
} 
+0

Могу ли я знать, почему этот вопрос был вниз проголосовали? – Apple

ответ

0
NSString *urlString = [NSString stringWithFormat:@"http://www.mouthshut.com/contest?ref=%@&inv_via=whatsapp&act=reg", UserName];  
     urlString = [urlString stringByReplacingOccurrencesOfString:@":" withString:@"%3A"]; 
     urlString = [urlString stringByReplacingOccurrencesOfString:@"/" withString:@"%2F"]; 
     urlString = [urlString stringByReplacingOccurrencesOfString:@"?" withString:@"%3F"]; 
     urlString = [urlString stringByReplacingOccurrencesOfString:@"," withString:@"%2C"]; 
     urlString = [urlString stringByReplacingOccurrencesOfString:@"=" withString:@"%3D"]; 
     urlString = [urlString stringByReplacingOccurrencesOfString:@"&" withString:@"%26"]; 

    //NSURL *url = [NSURL URLWithString:urlString]; 
    //urlString = [urlString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

    NSString * urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=Writing a review is better than whatsapp. Win cash prizes daily on MouthShut.com \n Join Now %@", urlString]; 

    NSURL * whatsappURL = [NSURL URLWithString:[urlWhats stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 

    if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) { 
     [[UIApplication sharedApplication] openURL: whatsappURL]; 
    } else { 
     UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Alert!" message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alert show]; 
    } 

 Смежные вопросы

  • Нет связанных вопросов^_^