Why is UIApplication not working in my Mac App
Asked Answered
K

3

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?

Keele answered 11/1, 2011 at 11:20 Comment(1)
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.Krol
M
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"]];
Munoz answered 11/1, 2011 at 11:49 Comment(0)
D
6

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

Driscoll answered 11/1, 2011 at 11:22 Comment(4)
wow so fast :D btw, where are the IBActions in interfacebuilder? i created them (appdelegate.h, then .m)Keele
Not sure I understand what you mean by asking where IBAction in InterfaceBuilder are. You just link IBAction with delegates on the inspector.Driscoll
i mean where are the actions?i know where they normally are in IB, look at my screenshot min.us/mvjgBiMKeele
You got here first, tío, he's all yours ;)Psychographer
P
2

try NSApplication

Psychographer answered 11/1, 2011 at 11:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.