2013-07-31 18 views
7

का उपयोग कर पाठ के साथ एक यूआरएल भेजना मैं व्हाट्सएप की कस्टम यूआरएल योजना का उपयोग कर यूआरएल के साथ कुछ पाठ भेजने की कोशिश कर रहा हूं। text:व्हाट्सएप यूआरएल योजना

NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%2C%20World!"]; 

समस्या आता है जब मुझे लगता है कि पाठ करने के लिए अपने खुद के यूआरएल संलग्न करना चाहते हैं वहाँ जाहिरा तौर पर केवल एक ही इस उद्देश्य के लिए वैध पैरामीटर है। मैं का उपयोग कर इसे सांकेतिक शब्दों में बदलना करने का विकल्प चुना इस:

NSString *encodedURLString = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(
                        NULL, 
                        (CFStringRef)urlAbsoluteString, 
                        NULL, 
                        (CFStringRef)@"!*'();:@&=+$,/?%#[]", 
                        kCFStringEncodingUTF8)); 

यूआरएल टेक्स्ट के बगल में WhatsApp के लिए भेजा जाता है, लेकिन WhatsApp के पक्ष में यह डीकोड नहीं प्राप्त करता है:

WhatsApp not decoding the URL

कोई भी विचार? धन्यवाद!

उत्तर

10

आप इसे सही तरीके से देख रहे हैं, लेकिन ऐसा लगता है कि यूआरएल डबल-एन्कोड किया जा रहा है। सुनिश्चित करें कि संदेश और यूआरएल दोनों एक बार एन्कोड किया गया है।

अपने समान कूट पद्धति का उपयोग करना, तुम इतनी तरह कुछ कर सकते हैं:

whatsapp://send?text=Hello%20World%21%20http%3A%2F%2Fyayvisitmysiteplease.com%3Ffunky%3Dparameter%26stuff 

WhatsApp में अपनी राह बनाता है कि आप जैसे ':

NSString *urlAbsoluteString = @"Hello World! http://yayvisitmysiteplease.com?funky=parameter&stuff"; 
NSString *encodedURLString = ... 

कि आप URL पर अमल करने देना चाहिए डी उम्मीद है। (मैं डबल सुनिश्चित करने के लिए सत्यापित।)

+0

OMG शेयर लिंक के लिए काम करेंगे टेक्स्ट और URL भेजने के लिए पूरा कोड है! वह वही था! मेरे पास "छुपा" था स्ट्रिंगबैडिंगपर्सेंटएस्केप यूजिंग एन्कोडिंग: 'एन्कोडिंग कॉल के बाद बाद में कॉल करें ... ओएमजी ... धन्यवाद !!! – Sendoa

10

यह दोनों WhatsApp

NSString * msg = @"Application%20Name%20https://itunes.apple.com/YOUR-URL"; 

    msg = [msg stringByReplacingOccurrencesOfString:@":" withString:@"%3A"]; 
    msg = [msg stringByReplacingOccurrencesOfString:@"/" withString:@"%2F"]; 
    msg = [msg stringByReplacingOccurrencesOfString:@"?" withString:@"%3F"]; 
    msg = [msg stringByReplacingOccurrencesOfString:@"," withString:@"%2C"]; 
    msg = [msg stringByReplacingOccurrencesOfString:@"=" withString:@"%3D"]; 
    msg = [msg stringByReplacingOccurrencesOfString:@"&" withString:@"%26"]; 

    NSString * urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@",msg]; 
    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 no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alert show]; 
    } 
में
+1

यह मेरे लिए काम नहीं करेगा – Jitendra

+1

यह मेरे लिए काम करता था, जबकि स्वीकृत उत्तर किसी भी तरह से नहीं किया गया था। –

+0

धन्यवाद। @ MuratÖgat –

2

यह पर क्या एप्लिकेशन

NSString * url = [NSString stringWithFormat:@"http://video...bla..bla.."]; 
url = (NSString*)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef) url, NULL,CFSTR("!*'();:@&=+$,/?%#[]"),kCFStringEncodingUTF8)); 

NSString * urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@",url]; 
NSURL * whatsappURL = [NSURL URLWithString:urlWhats]; 
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) { 
[[UIApplication sharedApplication] openURL: whatsappURL]; 
} else { 
// can not share with whats app 
} 
संबंधित मुद्दे