Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 应用程序没有';在转到后台之前无法保存_Iphone_Objective C_Background - Fatal编程技术网

Iphone 应用程序没有';在转到后台之前无法保存

Iphone 应用程序没有';在转到后台之前无法保存,iphone,objective-c,background,Iphone,Objective C,Background,每当用户进入后台时,我想在文本字段中保存一些文本。我想我写的所有内容都是正确的,因为我遵循了许多问题/答案。但是,当我关闭应用程序时,我的应用程序不会保存文本,甚至不会创建plist,因此当我重新打开它时,文本字段为空。代码如下: RootViewController.h: @interface RootViewController: UIViewController <UITextFieldDelegate> { UITextField *textField1; UITextFie

每当用户进入后台时,我想在文本字段中保存一些文本。我想我写的所有内容都是正确的,因为我遵循了许多问题/答案。但是,当我关闭应用程序时,我的应用程序不会保存文本,甚至不会创建plist,因此当我重新打开它时,文本字段为空。代码如下: RootViewController.h:

@interface RootViewController: UIViewController <UITextFieldDelegate> {
UITextField *textField1;
UITextField *textField2;
UITextField *textField3;
UITextField *textField4;
}
@property (nonatomic, retain) UITextField *textField1, *textField2, *textField3, *textField4;
@end
如果我改变这一点:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:@"UIApplicationDidEnterBackgroundNotification" object:myApp];
为此:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:myApp];

我收到一个错误,表明未声明UIApplicationIdentinterBackgroundNotification。

它不会在您尝试的方法中运行,因此在UIApplicationIdentinterBackground委托中。您所要做的就是在使用beginBackgroundTaskWithExpirationHandler进入后台时处理流程。请参阅本主题:

您尝试的第二个版本是使用此功能的正确方法,其中
UIApplicationIdentinterBackgroundNotification
是一个标识符而不是文字字符串。它应该在UIApplication.h中定义

你说你是在iPhone上编译的,所以听起来你的开发环境缺少这个定义。我自己也没试过,所以不能确定


一旦您通过了编译错误,我建议您使用NSLog查看代码的位置,因为这比查找要创建的文件更容易。

UIApplicationIdentinterBackgroundNotification
从iOS 4起就可以使用了。。。我想,这是它可能通过未声明错误的唯一原因……u提供的代码的问题是:因为我没有Mac,所以我在iPhone上制作项目,并使用移动终端编译。当我编译给定的代码时,会出现许多错误,包括“UIApplication可能不响应-endBackgroundTask:”您不需要beginBackgroundTaskWithExpirationHandler,只需将一些值保存在文件中即可。它适用于长时间运行的操作,并且应用程序必须接收一些事件,例如,如果它在睡觉前通过网络保存数据。我在哪里可以找到nslog结果?它会出现在设备的控制台日志中。关于如何阅读的各种建议如下:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:myApp];