2
PHPhotoLibrary.shared().performChanges({ () -> Void in

let request = PHAssetCreationRequest.forAsset()
request.addResource(with: .pairedVideo, fileURL: videoURL, options: nil)

request.addResource(with: .photo, fileURL: imageURL, options: nil)}, completionHandler: { (result : Bool, error : Error?) -> Void in
    if result {
        NSLog("save to camera roll as live photo")
    } else {
        if error != nil {
            print("something wrong when saving : %@", error!)
        }
    }
})

but, Error Domain=NSCocoaErrorDomain Code=-1 "(null)".How to fix it?

TheTiger
  • 13,264
  • 3
  • 57
  • 82
j.thome
  • 43
  • 4
  • why do you use `PHAssetResourceType(rawValue: 9)` instead of ".pairedVideo"? also i hardly recommend you to safe unwrap your variables, you will get nightmares believe me. Check all your variables in debug mode, anything `nil`? – Marcel T Apr 19 '18 at 06:44
  • Yeah,I edit it,still...no nil. – j.thome Apr 19 '18 at 06:51
  • https://github.com/genadyo/LivePhotoDemo . I hope you look at this example obviously there is a problem in the file you are saving and not in the code as you think – a.masri Apr 19 '18 at 07:19
  • Take a look at this [answer](https://stackoverflow.com/a/42033809/7245977) – DoesData Apr 19 '18 at 14:12

1 Answers1

-2

fixed.The jpg and mov must add metadata.

1.jpg,must add metadata: 17:UUID().uuidString

2.mov,must add metadata :com.apple.quicktime.content.identifier:UUID().uuidString

j.thome
  • 43
  • 4
  • 1
    Could you please add more information to your answer so that others can understand it properly? – TheTiger Apr 19 '18 at 12:45
  • No not in the comment add all the information in your answer. And just adding the link is not enough. You should add some text which highlights the issue and solution with the link you shared. Or delete your question as it will be a spam if it can not help others except you. – TheTiger Apr 19 '18 at 13:06
  • 1
    -1 please add detailed information, also consider, that a link can someday be a dead end. So in the future, most people won't understand anything from your answer. – Marcel T Apr 19 '18 at 13:24