2011-02-04 2 views
0

앱을 처음 열 때 동작보기를 표시하려고하는데이 방법을 잘 모르겠습니다.처음 만 표시되는 동작보기 만들기 처음 앱이 란

는 나는 내가 만든 액션 전망을

- (BOOL)application:(UIApplication *)application 
     didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

에 넣어해야 이해하지만, 결코 다시는 처음에 표시가 있고,하는 방법을 모르겠어요.

답변

0

응용 프로그램이 실행되었는지 여부를 기억해야한다면 이전에 actionview를 표시 할 수 있습니다. 한 가지 방법은 부울을 응용 프로그램 종료시 파일에 저장하고 응용 프로그램을 시작할 때 다시 읽는 것입니다 (존재하는 경우 응용 프로그램이 시작 되었음). 다음은 이와 같은 작업을 수행하는 코드입니다 (응용 프로그램 위임자에 넣으십시오).

여기
- (void)applicationWillResignActive:(UIApplication *)application { 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"saved_data.dat"]; 
NSMutableData *theData = [NSMutableData data]; 
NSKeyedArchiver *encoder = [[NSKeyedArchiver alloc] initForWritingWithMutableData:theData]; 
BOOL launched = YES; 
[encoder encodeBool:launched forKey:@"launched"]; 
[encoder finishEncoding]; 

[theData writeToFile:path atomically:YES]; 
[encoder release]; 
} 
저장하는

- (id) init { 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"saved_data.dat"]; 

NSFileManager *fileManager = [NSFileManager defaultManager]; 
if([fileManager fileExistsAtPath:path]) { 
    //open it and read it 
    NSLog(@"data file found. reading into memory"); 

    NSData *theData = [NSData dataWithContentsOfFile:path]; 
    NSKeyedUnarchiver *decoder = [[NSKeyedUnarchiver alloc] initForReadingWithData:theData]; 

    BOOL launched = [decoder decodeBoolForKey:@"launched"]; 
if (launched) { 
//APP HAS LAUNCHED BEFORE SO DON"T SHOW ACTIONVIEW 
} 

    [decoder finishDecoding]; 
    [decoder release]; 
} else { 
    NSLog(@"no data file found."); 
    //APP HAS NEVER LAUNCHED BEFORE...SHOW ACTIONVIEW 
} 
return self; 
} 

또한 시뮬레이터를 종료하면 시뮬레이터에서 실행중인이 코드가 실행되지 않을 경우, 당신이 실제로 누를 필요가 있습니다 ... 로딩을위한 코드입니다 iPhone 사용자와 같은 홈 버튼이됩니다.

+0

은 파일에 기록해야하며 그렇지 않으면 닫을 때도 부울 값을 유지할 수 있습니까? –

+0

시작부터 시작까지 어떤 방법으로 저장해야합니다 (백그라운드로 들어가서 다시 시작할 때 완전히 닫을 때가 아닐 수도 있습니다). 파일 저장은 나에게 가장 좋은 방법 인 것 같습니다. – Nitrex88