MPMediaLibraryDidChangeNotification occurring well after UIApplicationWillResignActiveNotification
===

ios api target: 4.2 - iphone: 3g

I am trying to get a UI notification to the user of my app that the media library has changed and its going to be a while till you can interact with the phone again. The current setup is:


    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
    ...
           [[NSNotificationCenter defaultCenter] addObserver:self
                                                    selector:@selector(iPodLibraryDidChange)
                                                        name: MPMediaLibraryDidChangeNotification
                                                      object:[MPMediaLibrary defaultMediaLibrary]];
            [[MPMediaLibrary defaultMediaLibrary] beginGeneratingLibraryChangeNotifications];
    ...
          [[NSNotificationCenter defaultCenter] addObserver: self
                                                    selector: @selector(willEnterBackground) 
                                                         name: UIApplicationWillResignActiveNotification
                                                       object: nil];
    }


    - (void)willEnterBackground
    {
        NSLog(@"This runs before it enters the background");
    }

    -(void)iPodLibraryDidChange
    {
     NSLog(@"Does this run before it hits the background?");
    }

The problems are:
- "iPodLibraryDidChange" isn't called until it is in the background already. Therefor it is too late to update the UI before it enters the background.
- If I make a call in "willEnterBackground", I can update the UI, but I can't make a check on if it's a library update because it is happening after.
- iPodLibraryDidChange will run a small amount of code that updates the UI /sometimes/ immediately after returning to active, but in iOS4, there is still a whole lot of background database work going on that pretty much locks down the phone. It is very inconsistant on what will run before the iOS background operations take over the phone.  ex. of what shows up in the console that iOS runs:

    [MPMediaLibraryDataProvider] Reloading data provider iPhone
    *** MLSSqliteVFS AllWrites ENABLED ***
    CPSqliteStatementPerform: attempt to write a readonly database for UPDATE ddd.ext_container SET orig_date_modified = (SELECT date_modified FROM container WHERE pid=container_pid) WHERE orig_date_modified=0
    CPSqliteStatementReset: attempt to write a readonly database for UPDATE ddd.ext_container SET orig_date_modified = (SELECT date_modified FROM container WHERE pid=container_pid) WHERE orig_date_modified=0
    CPSqliteStatementPerform: attempt to write a readonly database for DELETE FROM extras.db_schema_upgrade_info;
    CPSqliteStatementReset: attempt to write a readonly database for DELETE FROM extras.db_schema_upgrade_info;
    SQLite error in -[MLSQLCode _compiledSqliteStatementForConnection:preparedStatement:performStatement:splitIntoMultipleIfNecessary:]: attempt to write a readonly database in stmt:DELETE FROM extras.db_schema_upgrade_info;
    CPSqliteStatementPerform: attempt to write a readonly database for INSERT INTO extras.db_schema_upgrade_info (user_version, device_version) VALUES(?, ?);
    CPSqliteStatementReset: attempt to write a readonly database for INSERT INTO extras.db_schema_upgrade_info (user_version, device_version) VALUES(?, ?);
    SQLite error in -[MLSQLCode _compiledSqliteStatementForConnection:preparedStatement:performStatement:splitIntoMultipleIfNecessary:]: attempt to write a readonly database in stmt:INSERT INTO extras.db_schema_upgrade_info (user_version, device_version) VALUES(?, ?);
    [MPMediaLibraryDataProvider] Reloading data provider iPhone

Because for some reason iOS doesnt just tell you when it's done with all the library change operations, coupled with not having any control when they start happening, it makes for a pretty crappy situation for an end user (phone is locked up for 5-20 seconds w/o any indication of whats going on). 

Does anyone have a solution/workaround to this?

