How to use UIApp and NSApp for iphone application?

Hi! I am a newbie in iPhone apps development. Recently I was applying someone's engine to my application which has a line:
[NSApp terminate:self];

when I compile it, the error shows:
'NSApp undeclared'

I thought maybe it's because my application is for iphone, I changed it to:
[UIApp terminate:self];

but still the error says:
'UIApp undeclared'

Can anyone please let me know what's the problem? Thanks!

Mac Pro, Mac OS X (10.5.7)

Posted on Jul 25, 2009 8:04 PM

Reply
2 replies

Jul 25, 2009 8:51 PM in response to peterpenn

Hi, and welcome to the Dev Forums!

There isn't any UIApp in the iPhone UIKit, the application class is named UIApplication. However, while there was an undocumented terminate method in that class, I think it's been removed from the 3.0 SDK. The reason for this is that self-terminating apps violate the +iPhone Human Interface Guidelines+. The guidelines recommend putting up an alert message if an app can't continue. The user then terminates the app by pressing the Home button.

If you're not seeking to place your app in the Store, you can terminate it by calling exit(0).

Btw. there's no NSApp in the AppKit either. That application class is named NSApplication. Anyway, terminate is an instance method. There might be a define somewhere like:

#define NSApp [NSapplication sharedApplication]

- Ray

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to use UIApp and NSApp for iphone application?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.