【问题标题】:UIButton not working after openURL in ios 7ios 7中的openURL后UIButton不起作用
【发布时间】:2015-07-31 02:35:08
【问题描述】:

我有多个调用 openURL 的共享按钮。按下第一个按钮后,它会打开 Safari 进行共享,当我返回我的应用程序时,所有按钮都不起作用。 (仅 iOS 7.1,但 iOS 8 工作正常)

下面是我的代码:

- (IBAction)btnFacebook_TouchUpInSide:(id)sender
{
    NSLog(@"Touch FaceBook");

    NSString *shareUrl = @"some url";

    NSString *shareText = @"some text";

    NSString *shareDescription = @"some text";

    NSString *sharePictureUrl = @"some text";

    NSString *sharingURL = [self encodeURL:[NSString stringWithFormat:@"https://www.facebook.com/dialog/feed?app_id=388711667988471&display=page&caption=%@&description=%@&picture=%@&link=%@&redirect_uri=%@", shareText, shareDescription, sharePictureUrl, shareUrl, shareUrl]];

    if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:sharingURL]])
    {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:sharingURL]];
    }
}

- (IBAction)btnTwitter_TouchUpInSide:(id)sender
{
    NSLog(@"Touch Twitter");

    NSString *shareUrl = @"some url";

    NSString *shareText = @"some text";

    NSString *sharingURL = [self encodeURL:[NSString stringWithFormat:@"twitter://post?message=%@", [self encodeURL:[NSString stringWithFormat:@"%@ %@", shareUrl, shareText]]]];

    if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:sharingURL]])
    {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:sharingURL]];
    }
    else
    {
        NSLog(@"Open web to share twitter!");

        sharingURL = [NSString stringWithFormat:@"https://twitter.com/intent/tweet?url=%@&text=%@&count=none/",[self encodeURL:shareUrl],[self encodeURL:shareText]];

        if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:sharingURL]])
        {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:sharingURL]];
        }
    }
}

- (IBAction)btnPinterest_TouchUpInSide:(id)sender
{
    NSLog(@"Touch Pinterest");

    NSString *shareUrl = @"some url";

    NSString *shareText = @"some text";

    NSString *shareMedia = @"some text";

    NSString *sharingURL = [self encodeURL:[NSString stringWithFormat:@"pinit12://pinterest.com/pin/create/link/?url=%@&media=%@&description=%@", shareUrl, shareMedia, shareText]];

    if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:sharingURL]])
    {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:sharingURL]];
    }
    else
    {
        NSLog(@"Open web to share Pinterest!");

        sharingURL = [self encodeURL:[NSString stringWithFormat:@"https://www.pinterest.com/pin/create/link/?url=%@&media=%@&description=%@", shareUrl, shareMedia, shareText]];

        if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:sharingURL]])
        {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:sharingURL]];
        }
    }
}

- (IBAction)btnLinkedIn_TouchUpInSide:(id)sender
{
    NSLog(@"Touch LinkedIn");

    NSString *shareUrl = @"some url";

    NSString *shareTitle = @"some text";

    NSString *shareSummary = @"some text";

    NSString *shareSource = @"some text";

    NSString *sharingURL = [NSString stringWithFormat:@"https://www.linkedin.com/shareArticle?mini=true&url=%@&title=%@&summary=%@&source=%@",[self encodeURL:shareUrl],[self encodeURL:shareTitle],[self encodeURL:shareSummary],[self encodeURL:shareSource]];

    if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:sharingURL]])
    {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:sharingURL]];
    }
}

谢谢。

【问题讨论】:

    标签: ios objective-c uibutton ios7.1 openurl


    【解决方案1】:

    试试这个:

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:sharingURL]];
    

    而不是这个:

    if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:sharingURL]])
        {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:sharingURL]];
        }
    

    您将 openURL 移出 ifcanOpenURL

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多