IT TIP

Xcode 6은 각 실행 후 iOS8 시뮬레이터에서 내 앱의 디렉토리 이름을 계속 변경합니다.

itqueen 2020. 11. 5. 19:57
반응형

Xcode 6은 각 실행 후 iOS8 시뮬레이터에서 내 앱의 디렉토리 이름을 계속 변경합니다.


저는 Xcode 6 Beta 5를 실행하고 있지만 이것은 첫 번째 베타 이후로 발생했습니다. 시뮬레이터의 내 앱 디렉토리는 실행할 때마다 이름이 계속 변경됩니다. 이것을 알아내는 데 시간이 걸렸습니다. 나는 이것을 사용하여 doc의 dir 참조를 얻습니다.

NSString *folder = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                        NSUserDomainMask,
                                                        YES) lastObject];

NSLog(@"Documents Dir: %@",folder);

예를 들어 첫 번째 실행에서 다음과 같습니다.

/ Users / Joey / Library / Developer / CoreSimulator / Devices / 5B9930EE-A9B4-4B36-BABB-AA864ACAF2DE / data / Containers / Data / Application / 4B10C2E4-A5C3-4C64-93B1-4069FCCB9C46 / 문서

이제 두 번째 실행 :

/ Users / Joey / Library / Developer / CoreSimulator / Devices / 5B9930EE-A9B4-4B36-BABB-AA864ACAF2DE / data / Containers / Data / Application / 7E9EB62D-115A-4092-AD23-CB6BA3E5E10F / 문서

세 번째 실행 :

/ Users / Joey / Library / Developer / CoreSimulator / Devices / 5B9930EE-A9B4-4B36-BABB-AA864ACAF2DE / data / Containers / Data / Application / EC8F41E8-52ED-4B10-9808-B3ACC46FC6AA / Documents

이것은 앱 내의 특정 파일에 대한 경로 참조를 저장하기 때문에 내 앱에 혼란을 초래합니다. 내 NSLog 문이 잘못된 결과를 반환하는 것이 아니라 이것이 Finder에서 일어나는 일임을 확인했습니다. 매번 이름이 바뀝니다. 이런 일을 본 사람이 있습니까? 이것이 내가 오해하는 "기능"입니까?


Xcode 6은 실제로 실행될 때마다 앱의 UUID를 변경하며 절대 경로를 저장하는 데 잘못이 있습니다.


SIMPHOLDERS 사용

Xcode 5에서이 앱을 사용하면 Finder의 시뮬레이터에서 현재 실행중인 앱에 대한 Documents 폴더가 열립니다.

http://simpholders.com/

아직 Xcode 6에 대한 준비가되지 않았지만 (2014 년 9 월 24 일 현재)이 모든 번거 로움을 덜어줍니다.

Xcode 6 / iOS8에서 번들은 이제 데이터와 분리됩니다 ./ Xcode에서 실행되는 사이에 애플리케이션 GUID가 다시 생성됩니다 (이유는 확실하지 않음).

  DOCUMENTS DIR:/Users/gbxc/Library/Developer/CoreSimulator/Devices/AC79941F-EC56-495E-A077-773EEE882732/data/Containers/Data/Application/C220D351-0BE7-46BA-B35E-D16646C61A3F/Documents
mainBundlePath_:/Users/gbxc/Library/Developer/CoreSimulator/Devices/AC79941F-EC56-495E-A077-773EEE882732/data/Containers/Bundle/Application/12200D1D-9B67-408B-BCF7-38206CBE0940/myappname.app/BLANK_BLOG_SCALED.jpg

1. 시뮬레이터에서 장치 폴더 찾기

/Users/gbxc/Library/Developer/CoreSimulator/Devices/

각 /device.plist를 열어 어떤 GUID가 XCode에서 어떤 장치인지 확인하십시오.

3. iPad 2에서 실행중인 장치 찾기-고정 된 것 같습니다.

/Devices/AC79941F-EC56-495E-A077-773EEE882732

4. 애플리케이션 / Documents 폴더 찾기

/AC79941F-EC56-495E-A077-773EEE882732/data/Containers/Data/Application/C220D351-0BE7-46BA-B35E-D16646C61A3F/Documents

GUID C220D351-0BE7-46BA-B35E-D16646C61A3F는 앱이 XCode 6에서 실행될 때마다 다시 생성됩니다.

 NSArray *paths_ = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        if(paths_){
            _docsDir = [paths_ firstObject];
            DebugLog(@"DOCUMENTS DIR:%@",_docsDir);         
        }else{
            ErrorLog(@"paths_ is nil - cant get Documents directory");
        }

메인 번들 경로

NSString *mainBundlePath_ = [[NSBundle mainBundle] pathForResource:@"someimageinyourbundle" ofType:@"jpg"];
/AC79941F-EC56-495E-A077-773EEE882732/data/Containers/Bundle/Application/12200D1D-9B67-408B-BCF7-38206CBE0940/clarksonsiq.app/BLANK_BLOG_SCALED.jpg

실행 사이에 / Documents에 경로를 캐시하지 마십시오.

나는 그것을 plist에 연재하고 있었고 그들이 왜 계속 사라지는 지 알 수 없었습니다.

/ Documents 위의 GUID는 실행 사이에 계속 변경되지만 Finder에서 / Documents가 열려 있으면 폴더가 열린 상태로 유지됩니다.

https://devforums.apple.com/thread/235911?tstart=0

https://devforums.apple.com/thread/238754?tstart=0

무료 솔루션

오픈 소스 라이브러리 OpenSim을 사용 합니다. OpenSim은 Swift로 작성된 SimPholders를위한 오픈 소스 대안입니다.

유료 솔루션

SimPholder 애플리케이션을 사용하여 현재 애플리케이션 위치를 알 수 있습니다.

여기에 이미지 설명 입력

xcode 6.0의 경우>

SimPholder 2.0 alpha 2 다운로드


xcode 5.1 <

SimPholders 1.5 다운로드


이것이 iOS 8이 아닌 Xcode 6 관련임을 확인할 수 있습니다.

두 개의 개발 기계가 있습니다. 그중 하나에는 Xcode 5가 있습니다. 그 컴퓨터에서 항상 작업하고 있었고 URL은 괜찮 았습니다 (사진 앱, 사진이 표시됨).

어제 Xcode 6이 설치된 컴퓨터에서 git 내 소스를 확인했습니다. 내 사진이 더 이상 표시되지 않고 해당 앱 세션 중에 생성 된 사진 만 표시되는 것을 확인했습니다.

약간의 디버깅 후, 나는 file : /// var / mobile / Applications / B6A6BAEF-C90C-4A2A-93DB-E6700B88971F / Documents /가 모든 앱 실행에서 변경 된다는 것을 깨달았습니다 .

그동안 나는 iOS 7 장치로 작업하고 있습니다.

Xcode 5가 설치된 컴퓨터에서 한 번 더 확인하여 손에 넣을 때 확인하겠습니다.


DocumentDirectory (디렉터리 / 파일 이름) 내에 경로 만 저장하고 파일을로드 할 때마다 DocumentDirectory에 추가하면됩니다.

-(void)saveImage:(UIImage *)image{
NSData *pngData = UIImagePNGRepresentation(image);
NSString *pathInDocumentDirectory = [APP_DocumentDirectory stringByAppendingPathComponent:PROFILE_IMAGE_NAME];
NSString *filePath = [self documentsPathForFileName:pathInDocumentDirectory];
//Save pic file path - DirName/Filename.png
[XYZPreferencesHelper setUserImageFilePath:pathInDocumentDirectory];
 //Write the file
[[NSFileManager defaultManager] createFileAtPath:filePath contents:pngData attributes:nil];

}



-(void)loadSavedUserPicture{
//Load saved DirName/Filename.png
NSString *pathInDocumentDirectory = [XYZPreferencesHelper getUserImageFilePath];

if (pathInDocumentDirectory != nil){
    //Full path with new app Document Directory
    NSString *filePath = [self documentsPathForFileName:pathInDocumentDirectory];
    if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]){
        NSData *pngData = [NSData dataWithContentsOfFile:filePath];
        UIImage *image = [UIImage imageWithData:pngData];
        if (image != nil){
            userPicImageView.image = image;
        }

    }

 }
}



- (NSString *)documentsPathForFileName:(NSString *)name
{
NSString *documentsPath = [self createRestcallDirectoryIfNotExist];
return [documentsPath stringByAppendingPathComponent:name];
}



-(NSString *)createRestcallDirectoryIfNotExist{
NSString *path;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
path = [documentsPath stringByAppendingPathComponent:APP_DocumentDirectory];
NSError *error;
if (![[NSFileManager defaultManager] fileExistsAtPath:path])    //Does directory already exist?
{
    if (![[NSFileManager defaultManager] createDirectoryAtPath:path
                                   withIntermediateDirectories:NO
                                                    attributes:nil
                                                         error:&error])
    {
        NSLog(@"Create directory error: %@", error);
    }
}
return documentsPath;
}

참고 URL : https://stackoverflow.com/questions/25233386/xcode-6-keeps-renaming-my-apps-directory-in-ios8-simulator-after-each-run

반응형