xcode中设置及使用全局变量,需要分别设置AppDelegate.h和AppDelegate.m两个文件,在其它文件中调用时,先要引用上面的定义文件(#import "AppDelegate.h"),具体代码如下:
AppDelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
BOOL isApnsRun;
}
@property (strong, nonatomic) UIWindow *window;
@propertyBOOL isApnsRun;
@end
AppDelegate.m
@implementation AppDelegate
@synthesize isApnsRun;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
isApnsRun = true;
returnYES;
}
以上是完成定义,也可以是单独的文件用来保存这些定义;
调用:
AppDelegate *appDelegate=[[UIApplicationsharedApplication] delegate];
if (appDelegate.isApnsRun==true){
//
}