为什么我的按需资源仍处于“正在下载...”状态?

问题描述

enter image description here

我很确定这就是为什么未在此处调用我的完成代码块的原因:

 public function update($id){

    $item = Item::find($id);
    $statistic_id = 1;

   // to add

    $item->statistics()->attach($statistic_id,[
        'min' => 5,'max' => 10,'mandatory' => true
    ]);

    // to update
    $item->statistics()->updateExistingPivot($statistic_id,'mandatory' => true
    ]);
  }

我已经清理并重新启动了Xcode,还重新启动了iPhone和Macbook。没有任何帮助。我如何在这里清除它?

编辑

我已经打印了一些进度属性信息:

    resourceRequest = NSBundleResourceRequest(tags: Set(["preview"]))
    resourceRequest?.beginAccessingResources { [weak self] downloaded in //not called


        // here I do what I need with this and at the end I call      
        // self?.resourceRequest?.endAccessingResources()
        
    }

但是当我打电话给print(resourceRequest?.progress.isCancelled) //false print(resourceRequest?.progress.isPaused) //false print(resourceRequest?.progress.isFinished) //false print(resourceRequest?.progress.isIndeterminate) //false print(resourceRequest?.progress.localizedDescription) //0% completed print(resourceRequest?.progress.isCancellable) //true 时,什么都没有改变...

如何拒绝,取消或恢复该请求?

打印进度时,我有

cancel()

解决方法

希望您已经检查了此注意事项

您必须先访问此方法或有条件地调用BeginAccessingResources(completionHandler :),然后再访问由请求管理的标记所标记的任何资源。

func conditionallyBeginAccessingResources(completionHandler: @escaping (Bool) -> Void)

如苹果建议在链接下方的复选标记之前做的

Please check this checkpoint

,

设备上的磁盘是否有可能已满? The documentation提供了一个方便的小片段,用于注册通知并进行检查。

在此处复制

清单4-11注册NSBundleResourceRequestLowDiskSpaceNotification通知


    // Register to call self.lowDiskSpace when the notification occurs
    [[NSNotificationCenter defaultCenter]
        addObserver:self
           selector:@selector(lowDiskSpace:)
               name:NSBundleResourceRequestLowDiskSpaceNotification
             object:nil
    ];

    // Notification handler for low disk space warning
    -(void)lowDiskSpace:(NSNotification*)theNotification
    {
        // Free the lower priority resource requests
        for (NSBundleResourceRequest *atRequest in self.lowPriorityRequests) {
            // End accessing the resources
            [atRequest endAccessingResources];
        }
     
        // clear lowPriorityRequests preventing multiple calls to endAccesingResource
        [self.lowPriorityRequests removeAllObjects];
    }