container identifier 이름을 잘 지으세요 !
참고:
https://developer.apple.com/help/account/manage-identifiers/create-an-icloud-container/
⁉️ iCloud.com.example.appName
라고 추천을 하는데는 이유가 있다.
icloud에 업로드를 해도 icloud drive폴더에서 보이지 않았었는데, 이유는 바로 이것때문,,,
저 iCloud. 뒤에를 bundle identifier와 동일한걸로 써주면 된다.
참고:
https://developer.apple.com/documentation/cloudkit/enabling_cloudkit_in_your_app#3403831
info.plist에 추가 필수
<key>NSUbiquitousContainers</key>
<dict>
<key>iCloud.com.example.appName</key>
<dict>
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
<true/>
<key>NSUbiquitousContainerName</key>
<string>보여주고 싶은 폴더 명</string>
<key>NSUbiquitousContainerSupportedFolderLevels</key>
<string>Any</string>
</dict>
</dict>
그 후 ios/Runner 에 .entitlements 에 맞게 들어가 있는 지 확인하기!
<key>com.apple.developer.icloud-container-identifiers</key>
<key>com.apple.developer.icloud-services</key>
<array>
<string>CloudDocuments</string>
</array>
<key>com.apple.developer.ubiquity-container-identifiers</key>
<array>
<string>iCloud.com.example.appName</string>
</array>
icloud 저장소 관리 패키지가 있지만...
https://pub.dev/packages/icloud_storage
upload를 해도 왜인지 icloud drive에서 파일이 보이질 않음.
icloud를 사용하는 앱에 뜨고, 용량도 뜨지만 icloud drive에서 볼 수 가 없음.
그래서 method channel를 사용 swift로 처리하게 되었다.
method channel 사용은 나중에 따로 더 정리해봐야겠다!
dart
if(Platform.isIOS){
icloudUpload('${upload할 file path}');
};
Future<void> icloudUpload(String filePath) async {
print("icloud upload");
final MethodChannel _channel = const MethodChannel("-.-.-");
String path = "";
final result = await _channel
.invokeMethod("uploadtoicloud", {"path":filePath});
path = result;
print(path);
}
참고로 mp4파일을 업로드했다.(그러나 icloud drive에 용량이 큰 파일을 저장하는 것은 좋지 않다고 한다..? 이러한 이유로 그냥 공부하고 검토로 끝나게 되었다.)
그 후 저장시에 icloud drive에 폴더가 생성되고 파일이 올라가는 것을 확인 할 수 있었다! 사실 identifier 이름 때문에 안보여서 고생이었지, 바꾸고 나니 슥슥 잘되었다.
다만 swift 코드로 많은 걸 한건 아니지만, 한번도 사용해본 적이 없어서 많이 헤맸다.
안드로이드는 java가 익숙하니깐 네이티브로 해도 금방되는데 ios는 파일구조도 잘 모르겠고 문법도 모르고...
swift 문법을 좀 익혀봐야겠다!