8

i am using openURL for my iphone apps, works perfectly, but now i want to use it on mac, normally, i use this code

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://google.com"]];

and it works perfectly in Xcode for iPhone app, but when doing a mac app, it gets me this error:

"UIApplication" undeclared (first use in this function)

So help anyone?

Abizern
  • 146,289
  • 39
  • 203
  • 257
Cykey
  • 81
  • 1
  • 3
  • 2
    UI library is used only for iPhone, iPad and iPod touch device development.And NSApplication is only used for mac desktop development applications. Therefore you must have used NSApplication instead of UIApplication. – Tirth Jan 11 '11 at 11:34

3 Answers3

19

As others have said, UIApplication is part of UIKit, a Cocoa Touch framework for iOS. On the Mac, you have to use AppKit, a Cocoa framework for Mac OS X, which provides NSApplication.

That being said, if you want to open a URL you need to use NSWorkspace:

[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://google.com"]];
6

You can't use UIApplication. You need to use NSApplication instead.

Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
2

try NSApplication

Abizern
  • 146,289
  • 39
  • 203
  • 257