2byte language problem in iOS 10.3

I tested our app on iOS 10.3

In previous versions, our app was fine.

Our app saves the streamed video as mp4 video file having korean filename in the Document folder in the App.

and then moves it to the video album after saving. It was normal.

But In this version when it have korean file name, Save file is fine, but It can not moved to album.

Does anyone have this problem? Below is our test code.

If it is a 10.3 issue, please fix it.

Or Do you have any recommendation method for fixing this problem?


File Creation Method .


NSString *cameraName = self.currentCamera.name;

NSString *path = [NSString stringWithFormat:@"%@_rec_%@.mp4", cameraName, [self createCurrentDateString]];

const char *filename = [path UTF8String];

mFd = open(filename, O_CREAT /| O_LARGEFILE*/ | O_TRUNC | O_RDWR, 00666);



Save To Album Method


- (void) saveFileToAlbumWithPath:(NSString*) directory path:(NSString*)path {

__block PHFetchResult *photosAsset;

__block PHAssetCollection *collection;

__block PHObjectPlaceholder *placeholder;

PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];

fetchOptions.predicate = [NSPredicate predicateWithFormat:@"title = %@", directory];

collection = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum

subtype:PHAssetCollectionSubtypeAny

options:fetchOptions].firstObject;


[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{

PHAssetChangeRequest *assetRequest;

/

if([directory isEqualToString:HOMECAME_RECORD]){

assetRequest = [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:[NSURL fileURLWithPath:path]];

}else{

assetRequest = [PHAssetChangeRequest creationRequestForAssetFromImageAtFileURL:[NSURL fileURLWithPath:path]];

}

placeholder = [assetRequest placeholderForCreatedAsset];

photosAsset = [PHAsset fetchAssetsInAssetCollection:collection options:nil];

PHAssetCollectionChangeRequest *albumChangeRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:collection assets:photosAsset];

[albumChangeRequest addAssets:@[placeholder]];

} completionHandler:^(BOOL success, NSError *error) {

if (success) {

dispatch_async(dispatch_get_main_queue(), ^{

if([directory isEqualToString:HOMECAME_RECORD]){

[self.view makeToast:commonStr(@"toast_monitoring_saved_recording_file") duration:2.0f position:CSToastPositionBottom];

} else {

[self.view makeToast:commonStr(@"toast_monitoring_saved_screenshot") duration:2.0f position:CSToastPositionBottom];

}

});

} else {

dispatch_async(dispatch_get_main_queue(), ^{

if([directory isEqualToString:HOMECAME_RECORD]){

[self.view makeToast:commonStr(@"toast_monitoring_fail_saved_recording") duration:2.0f position:CSToastPositionBottom];

} else {

[self.view makeToast:commonStr(@"toast_monitoring_fail_saved_screenshot") duration:2.0f position:CSToastPositionBottom];

}

});

NSLog(@"Failed to save media file error :%@", error);

}

}];

}

Accepted Reply

Hello again haewookjung,

I don't understand your reply or the specifics of what your app is doing. Even if the encoding is incorrect, or if you are using some non-POSIX method, you can still create a file. It just may not be exactly what it should be. You may not be able to tell the difference by looking at the name. The only way to tell for sure if it is an encoding problem is to use the correct API. Then if you still have a problem, you can investigate further. But you can't even begin to debug until you start using "fileSystemRepresentation". Using "UTF8String" for POSIX files is simply wrong. Many people do it anyway and it works for them becaue they are using languages like English.

Replies

Hello haewookjung,

When going from Cocoa directly to POSIX like this, you can't just call "UTF8String". The low-level Unicode in the HFS+ filesystem is too specific for that. Instead, try calling "fileSystemRepresentation" on the NSString.

Dear john

Thank you for your answer

but If it cannot be created file having korean in the document folder, I can understand about your answer.

But the file can create in the document folder using POSIX api, and I can play that file.

This problem occurs only when I try to move a file created in the Document folder to an album normal file containing Korean.

Is it also UTF8string problrm?

Hello again haewookjung,

I don't understand your reply or the specifics of what your app is doing. Even if the encoding is incorrect, or if you are using some non-POSIX method, you can still create a file. It just may not be exactly what it should be. You may not be able to tell the difference by looking at the name. The only way to tell for sure if it is an encoding problem is to use the correct API. Then if you still have a problem, you can investigate further. But you can't even begin to debug until you start using "fileSystemRepresentation". Using "UTF8String" for POSIX files is simply wrong. Many people do it anyway and it works for them becaue they are using languages like English.