3

When I plug in the iPhone to iTunes and drag a file into the File Sharing section of my app, the app on the screen goes away for a moment and then comes back. It seems that none of the app delegate methods are triggered at this time, not even something like "went to background, went to foreground".

As soon as my app comes back after a sync where the user added or removed files, I want to update the screen.

Maybe there is a notification beeing sent?

Proud Member
  • 40,078
  • 47
  • 146
  • 231

3 Answers3

6

Also, <MediaPlayer/MediaPlayer.h> framework's [MPMediaLibary defaultMediaLibrary] can post notification MPMediaLibraryDidChangeNotification, which is fired especially when your media library is updated while your device is syncing with iTunes.

You can let your object to observe this notification by adding:

#import <MediaPlayer/MediaPlayer.h>

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(<#selector#>:) name:MPMediaLibraryDidChangeNotification object:[MPMediaLibrary defaultMediaLibrary]];

Also make sure to activate this notification by using - (void)beginGeneratingLibraryChangeNotifications

petershine
  • 3,190
  • 1
  • 25
  • 49
  • This doesn't work for iTunes File Sharing. It's not triggered. Seems to be only for stuff in the camera roll, or maybe videos / music. But not app-specific docs. Tested on iPad in iOS5. – openfrog Nov 16 '11 at 23:07
  • This used to work in iOS4 for iTunes File Sharing. As of iOS5 it seems to be deprecated, or possibly broken. – skantner Dec 02 '11 at 19:19
  • Added an important information to use this notification correctly. However, it's quite possible that it's not working for iOS 5, since syncing is done without putting the application to be in background, making the notification not really needed. But it's still in the document and no deprecated mark is written for this notification and its method – petershine Dec 03 '11 at 06:37
4

- (void)applicationWillResignActive:(UIApplication *)application is called when the sync starts and - (void)applicationDidBecomeActive:(UIApplication *)application after the sync is complete

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
1

applicationWillResignActive does not work starting with iOS 5.0.

You can use the DirectoryWatcher class in the DocInteraction sample app.

pstoppani
  • 2,531
  • 1
  • 20
  • 20
  • The DirectoryWatcher class doesn't notify it's callback when the sync or file transfer is complete - only when a new file is created. Is there some way to notify when the transfer is complete (think of a large file)? – mdupls Oct 21 '11 at 14:20
  • My hack to knowing when the sync is complete is to use a timer to watch the file's size; when it stops changing, I assume the sync is complete. – pstoppani Nov 18 '11 at 17:13