iPhone App在模拟器中工作但在设备上不起作用(NSUserDefaults)

时间:2010-10-19 20:52:46

标签: iphone objective-c ios-simulator nsuserdefaults

我有一些代码,它在模拟器中运行得很完美,但是我无法在真正的iPhone设备上运行它,我不明白这个原因:

- (void)loadView {
 self.title = @"Optionen";
 [super loadView];
}

- (void)viewDidLoad {    
 [super viewDidLoad];

 NSMutableArray *strArray = [NSMutableArray new];
 NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

 if ([[prefs stringForKey:@"facebook"] length] > 0 ) {
  [strArray addObject: [prefs stringForKey:@"facebook"]];
 }
 else {
  [strArray addObject:@"YES"];
 } 


 if ([[prefs stringForKey:@"twitter"] length] > 0 ) {
  [strArray addObject: [prefs stringForKey:@"twitter"]];
 }
 else {
  [strArray addObject:@"YES"];
 }


 if ([[prefs stringForKey:@"pm"] length] > 0 ) {
  [strArray addObject: [prefs stringForKey:@"pm"]];
 }
 else {
  [strArray addObject:@"YES"];
 }

 [facebookSwitch setOn:[[strArray objectAtIndex:0] boolValue]];
 [twitterSwitch setOn:[[strArray objectAtIndex:1] boolValue]];
 [pmSwitch setOn:[[strArray objectAtIndex:2] boolValue]]; 

 [strArray release];
}

-(IBAction) change:(id) sender {
 NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

 if (facebookSwitch.on) {
  [prefs setObject:@"YES" forKey:@"facebook"];  
 }
 else {
  [prefs setObject:@"NO" forKey:@"facebook"];
 }


 if (twitterSwitch.on) {
  [prefs setObject:@"YES" forKey:@"twitter"];  
 }
 else {
  [prefs setObject:@"NO" forKey:@"twitter"];
 }


 if (pmSwitch.on) {
  [prefs setObject:@"YES" forKey:@"pm"];  
 }
 else {
  [prefs setObject:@"NO" forKey:@"pm"];
 }

 [prefs synchronize];
}

使用NSUserDefaults会出现问题吗?

感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

您应该检查崩溃日志:

Auto upload crashlogs iPhone