//获取全局的Delegate对象,这样我们可以调用这个对象里的方法和变量
[[UIApplication sharedApplication] delegate];
//获得程序的主Bundle
NSBundle *bundle = [NSBundle mainBundle];
/*
在程序中播放声音
1.添加AudioToolbox框架
*/
NSString *path = [bundle pathForResource:@"soundFileName" ofType:@"wav"];
SystemSoundID soundId;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)([NSURL URLWithString:path]), &soundId);
AudioServicesPlayAlertSound(soundId);
//捕捉程序关闭或者进入后台事件
UIApplication *application = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:application];
}
- (void)applicationWillResignActive:(NSNotification *)noti{
}
#pragma mark -- 获取截屏
- (UIImage *)getScreenShot{
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}