4

I am trying to open one URL in Safari from my App when App is in background, below is my code

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

My App is hiting the above line during debugging, but not opening Safari with the given URL.

Sudheer Kumar Palchuri
  • 2,919
  • 1
  • 28
  • 38
  • UIKit calls can only run on the main thread. I think that because this is running on a background thread, Safari still visits the URL, but your app is still active. Try opening Safari shortly after and see if it loaded the URL. The solution would be to put this on the main thread, and thus leave your app at the time that code is run. That doesn't sound like what you want it to do, sorry. If you want to visit the URL from within your app you can present an UIWebView. – Mohit Aug 05 '14 at 07:09
  • if([[UIApplication sharedApplication]canOpenURL:url]) { [[UIApplication sharedApplication]openURL:url]; } – Mohit Aug 05 '14 at 07:09
  • @MohitPopat: I tried to run the above line of code on MainThread, eventhough it didn't work and our client don't want to show in UIWebView, they prefer only Safari. – Sudheer Kumar Palchuri Aug 05 '14 at 07:20
  • Did you try this `system([[NSString stringWithFormat:@"uiopen \"%@\"", myUrlToOpen] UTF8String]);` – Mohit Aug 05 '14 at 07:24
  • this command will not work on simulator. it will work only on jailbreak device – Mohit Aug 05 '14 at 07:27
  • check this...http://stackoverflow.com/questions/4170254/uiapplication-openurl-background –  Aug 05 '14 at 07:38
  • @MohitPopat: I had a iPod4 (iOS6.1.5) jailbroken device, tried the system command your provided instead of openURL method, it didn't work at all. – Sudheer Kumar Palchuri Aug 05 '14 at 09:09

1 Answers1

1

It's not possible, You cannot launch another app from the background state. If app in background then you can't have any event for handle your app event from iPhone/iPad screen. You must have to wake up your app. You can use local notifications.

Tapas Pal
  • 7,073
  • 8
  • 39
  • 86