web-dev-qa-db-ja.com

Xcode 6は、実行のたびにiOS8シミュレーターでアプリのディレクトリの名前を変更し続けます。

私はXcode 6 Beta 5を実行していますが、これは最初のベータ以来起こっています。シミュレーター内のアプリのディレクトリは、実行のたびに名前が変更され続けます。これを理解するにはしばらく時間がかかりました。これを使用して、ドキュメントのディレクトリ参照を取得しています。

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/Documents

2回目の実行は次のとおりです。

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

3回目の実行:

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

これは、アプリ内の特定のファイルへのパス参照を保存するため、私のアプリに大混乱をもたらしています。 NSLogステートメントが間違った結果を返しているわけではなく、これがFinderで発生していることを確認しました。毎回名前を変えています。誰もこれが起こるのを見ましたか?これは私が誤解している「機能」ですか?

69
Joseph Toronto

実際、Xcode 6は実行ごとにアプリのUUIDを変更し、絶対パスを保存するのは間違っています。

49
Joseph Toronto

SIMPHOLDERSを使用

Xcode 5でこのアプリを使用すると、シミュレータで現在実行中のアプリのFinderでDocumentsフォルダが開きます。

http://simpholders.com/

xcode 6にはまだ対応していません(2014年9月24日現在)が、この面倒をすべて軽減します。

Xcode 6/iOS8では、バンドルはデータから分離されました。/アプリケーションGUIDはXcodeの実行間で再生成されます(理由は不明)

  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
8
brian.clear

無料ソリューション

Open Source Library OpenSim を使用します。 OpenSimは、Swiftで記述されたSimPholdersのオープンソースの代替です。

有料ソリューション

SimPholderアプリケーションを使用して、現在のアプリケーションの場所を確認します。

enter image description here

Xcode 6.0の場合>

ダウンロード SimPholder 2.0 alpha 2


Xcode 5.1の場合<

ダウンロード SimPholders 1.5

7
Paresh Navadiya

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;
}
1
Shlomi Fresko

これはiOS 8ではなくXcode 6に関連していることを確認できます。

2台の開発マシンがあります。そのうちの1つにはXcode 5があります。そのマシンで常に作業をしていましたが、URLは正常でした(写真アプリ、写真が表示されています)。

昨日、Xcode 6を搭載したマシンでソースをgit形式でチェックインしました。アプリのセッション中に作成された写真のみが表示されていることに気付きました。

少しデバッグした後、file:/// var/mobile/Applications/B6A6BAEF-C90C-4A2A-93DB-E6700B88971F/Documents /がアプリの実行ごとに変化していることに気付きました。

その間ずっと、iOS 7デバイスで作業しています。

Xcode 5を搭載したマシンでもう一度チェックして、手に入れたときを確認します。

1
vale4674