![](/img/trans.png)
[英]Parse.com: PFQuery querying data from PFUser currentUser
[英]Parse.com + iOS Avoid simultaneous calls of PFQuery to avoid NSInternalInconsistencyException error crash
重復項:
已經使用Parse.com實現了iOS應用
嘗試從緩存中檢索。
從緩存中檢索數據時,出現如下錯誤:
由於未捕獲的異常“ NSInternalInconsistencyException”而終止應用程序,原因:“此查詢具有出色的網絡連接。 您必須等到完成為止。
當我瀏覽問題時,我發現:
有人建議,可能是由於對同一個查詢對象進行了兩次查詢調用而沒有等待第一個查詢完成而發生的。
如何避免在這個程序中的這些simultatanius電話
查詢setLimit:限制]; [查詢setSkip:跳過];
//RETRIEVING FROM CACHE query.cachePolicy = kPFCachePolicyCacheThenNetwork; [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { if (!error) { [allObjects removeAllObjects]; //Added regarding cache ****** // The find succeeded. Add the returned objects to allObjects [allObjects addObjectsFromArray:objects]; if (objects.count == limit) { // There might be more objects in the table. Update the skip value and execute the query again. skip += limit; [query setSkip: skip]; // Go get more results weakPointer(); } else { // We are done so return the objects block(allObjects, nil); } } else { block(nil,error); } }];
為了避免同時調用PFQuery,請在調用findObjects
之前調用[query cancel]
:
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
[query cancel]; //cancels the current network request being made by this query (if any)
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
//do stuff
}];
小心:
[query cancel];
如果您期望回調,則不起作用。
解:
@property (nonatomic) BOOL isCurrentlyFetching; // Makes sure Parse is called only
-(void)myQuery
{
if (_isCurrentlyFetching) { return; } // Bails if currently fetching
_isCurrentlyFetching = YES;
//RETRIEVING FROM CACHE
query.cachePolicy = kPFCachePolicyCacheThenNetwork; // Whatever your cache policy is
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error){
// Your code...
}
else{
// Your code...
}
_isCurrentlyFetching = NO;
}];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.