---
title: "IOS, button not work after openURL in ios 7"  
description: "IOS, button not work after openURL in ios 7"  
author: "Anonymous User"  
published: 2015-07-31  
updated: 2015-08-01  
canonical: https://www.mindstick.com/forum/33386/ios-button-not-work-after-openurl-in-ios-7  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# IOS, button not work after openURL in ios 7

I [coding](https://www.mindstick.com/articles/12290/teaching-coding-from-the-metal-up-or-from-the-glass-back) a [ios app](https://www.mindstick.com/forum/160260/what-is-the-best-place-to-hire-an-ios-app-developer), it have muti [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) share by openURL. After fisrt button press, it open safari for share, and when I back to my app, all button is not work. (only ios 7.1, but ios 8 worked fine)

This is my code:

```
-(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]];
    }
}
```

Thanks in advance...

## Replies

### Reply by Anonymous User

Try this:

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

instead of this:

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

With that you move openURL out of if block canOpenURL


---

Original Source: https://www.mindstick.com/forum/33386/ios-button-not-work-after-openurl-in-ios-7

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
