One-way file transfer: when to cleanup the source file?

I'm using Watch Connectivity to transfer files from the Watch to its paired iOS device. File transfer is successful in my first tests, but obviously I need to erase the source file when it is - successfully - sent.

When should I do that?

  • just after initiating the file transfer, using transferFile(file: NSURL, metadata: [String : AnyObject]) when getting the returned WCSessionFileTransfer?
  • when getting the callback func session(_ session: WCSession, didFinish fileTransfer: WCSessionFileTransfer ? --> but will the callback always be called, even if the transfer finishes while the app is in background?
  • some other time?

NB: I'd really want to avoid implementing a custom 'ack' system, thus not using any user info/application context transfer.

Replies

Hi there!

If you delete the source file just after you initiate the transfer, then you'll lose all of the files from the Watch that don't transfer successfully.

Your best option is to delete the file when you get the callback that the file transfer completed. If the transfer was successful, you should be able to delete the file at that time.

  • Hi! Thank you for your help, but one important detail is missing, hence the 2nd bullet in the original post: will the callback always be called at some time, even if the transfer finishes while the app is in background? Thanks a lot!

  • Yes! It should be called. If you run into a problem with that, please file Feedback so we can address it!

Add a Comment