如何在iOS应用程序的什么应用程序上分享链接和短信?

Aar*_*Oza 2 objective-c ios whatsapp

我试图从我的iOS应用程序发送短信应用程序的短信,但它没有成功.我在下面添加了我的代码,请告诉我我做错了什么.我的设备安装了什么应用,但我仍然无法发送任何短信.

- (IBAction)whatAppInvite:(id)sender
    {
        NSString * strTextPost = [@"" stringByAppendingFormat:@"Hey try this app. Its amazing. \n\n https://itunes.apple.com/us/app/google-search/*********2?mt=8"];


        strTextPost = [strTextPost stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
        strTextPost = [strTextPost stringByReplacingOccurrencesOfString:@":" withString:@"%3A"];
        strTextPost = [strTextPost stringByReplacingOccurrencesOfString:@"/" withString:@"%2F"];
        strTextPost = [strTextPost stringByReplacingOccurrencesOfString:@"?" withString:@"%3F"];
        strTextPost = [strTextPost stringByReplacingOccurrencesOfString:@"," withString:@"%2C"];
        strTextPost = [strTextPost stringByReplacingOccurrencesOfString:@"=" withString:@"%3D"];
        strTextPost = [strTextPost stringByReplacingOccurrencesOfString:@"&" withString:@"%26"];
        strTextPost = [strTextPost stringByReplacingOccurrencesOfString:@"." withString:@"%2E"];
        strTextPost = [strTextPost stringByReplacingOccurrencesOfString:@"'" withString:@"%27"];
        strTextPost = [strTextPost stringByReplacingOccurrencesOfString:@"-" withString:@"%2D"];

        NSString * urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@",strTextPost];

        NSURL * whatsappURL = [NSURL URLWithString:urlWhats];
        if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]])
        {
            if ([[UIApplication sharedApplication] canOpenURL: whatsappURL])
            {
            [[UIApplication sharedApplication] openURL: whatsappURL];
            }
            else
            {
                // don't know what happens
                // calls this
            }
        }
        else
        {
            UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];
        }

    }
Run Code Online (Sandbox Code Playgroud)

Jay*_*ani 8

试试这段代码:

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];
}
Run Code Online (Sandbox Code Playgroud)