Skip to content

Commit

Permalink
iOS. + '_query = nil;'
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-tsx committed Apr 13, 2023
1 parent dc2d83d commit 006eec3
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions ios/RNCloudFs.m
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ - (void)getIcloudDocumentRecurse
NSMetadataQuery *query = [notification object];
[query disableUpdates];
[query stopQuery];
_query = nil;

if ([query resultCount] < 1) {
return resolver(nil);
Expand Down Expand Up @@ -291,6 +292,7 @@ - (void)getIcloudDocumentRecurse
NSMetadataQuery *query = [notification object];
[query disableUpdates];
[query stopQuery];
_query = nil;

if ([query resultCount] < 1) {
return resolver(nil);
Expand Down Expand Up @@ -541,16 +543,6 @@ - (BOOL)startFileDownloadIfNotAvailable:(NSMetadataItem*)item {
[_query setSearchScopes:@[NSMetadataQueryUbiquitousDocumentsScope, NSMetadataQueryUbiquitousDataScope]];
[_query setPredicate:[NSPredicate predicateWithFormat: @"%K LIKE '*'", NSMetadataItemFSNameKey]];


dispatch_async(dispatch_get_main_queue(), ^{

BOOL startedQuery = [self->_query startQuery];
if (!startedQuery)
{
reject(@"error", @"Failed to start query.\n", nil);
}
});

[[NSNotificationCenter defaultCenter] addObserverForName:
NSMetadataQueryDidFinishGatheringNotification
object:_query
Expand All @@ -560,12 +552,22 @@ - (BOOL)startFileDownloadIfNotAvailable:(NSMetadataItem*)item {
NSMetadataQuery *query = [notification object];
[query disableUpdates];
[query stopQuery];
_query = nil;

for (NSMetadataItem *item in query.results) {
[self startFileDownloadIfNotAvailable: item];
}

return resolve(@YES);
}];

dispatch_async(dispatch_get_main_queue(), ^{
BOOL startedQuery = [self->_query startQuery];
if (!startedQuery)
{
reject(@"error", @"Failed to start query.\n", nil);
}
});
}

@end

0 comments on commit 006eec3

Please sign in to comment.