Domanda

Whenever my document is renamed , autosaving is blocked and the first save after the rename presents the pictured message.

enter image description here

Technically its not an issue as either button takes the user back to a autosavable state but it is confusing for my users.

I have tried hooking the method

-(void)moveToURL:(NSURL *)url completionHandler:(void (^)(NSError *))completionHandler
{
    void(^takeoverblock)(NSError *error) = ^(NSError *error){

        if (completionHandler) {
            completionHandler(error);
        }

        if (!error) {

            [self updateChangeCountWithToken:[self changeCountTokenForSaveOperation:NSAutosaveInPlaceOperation] forSaveOperation:NSAutosaveInPlaceOperation];
        }

    };

    [super moveToURL:url completionHandler:takeoverblock];
}

and using various flavours of updateChangeCount: and updateChangeCountWithToken: but the warning consistently appears.

How do I put the document in a state where it resumes standard autosave behaviour after a rename/move.?

È stato utile?

Soluzione

The answer via a friendly Apple engineer is this appears when the modificationDate on the underlying sqlite file is different to the fileModificationDate property on the NSPersistentDocument instance so to resolve reset the fileModificationDate after the move

override moveToUrl: like this

-(NSDate *)modDateForURL:(NSURL *)url
{
    NSDictionary *dict = [[NSFileManager defaultManager] attributesOfItemAtPath:[url path] error:NULL];
    return dict[NSFileModificationDate];
}


-(void)moveToURL:(NSURL *)url completionHandler:(void (^)(NSError *))completionHandler
{

    void(^takeoverblock)(NSError *error) = ^(NSError *error){

        if (completionHandler) {
            completionHandler(error);
        }

        if (!error) {

            self.fileModificationDate = [self modDateForURL:self.fileURL];

        }

    };

    [super moveToURL:url completionHandler:takeoverblock];
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top