objective c - How can I cast my NSURLSessionDownloadTask to my custom NSURLSessionDownloadTask (inheritance)? -
i have created custom nsurlsessiondownloadtask named vjsessiontask , have added custom things type (enum) , custom object (id):
@interface vjsessiontask : nsurlsessiondownloadtask typedef enum types { ls, lsh, dl, ul, rm, th } type; @property enum types type; @property (strong, nonatomic) id customobject; @property (strong, nonatomic) nsstring *progressnotif; @property (strong, nonatomic) nsstring *donenotif; @property (strong, nonatomic) nsurl *tmpfile; @end
and when this:
vjsessiontask *tasksession = (vjsessiontask *)[self.prioritysession downloadtaskwithrequest:listfilerequest]; // init tasksession type tasksession.type = ls;
i error:
-[__nscflocaldownloadtask settype:]: unrecognized selector sent instance 0x1556198f0
then come don't understand or don't know how that... give thanks in advance ;)
nsurlsessiontasks not strictly speaking subclass-able unfortunately. evident in scheme can queue info task , homecoming nscflocaldownloadtask (presumably meaning task homecoming content cache).
the best way go doing borrow on architectural decision of afnetworking , have individual taskdelegates monitor responses individual task works on. when want find info relating task can query dictionary of taskdelegates. each task has unique identifier can utilize key dictionary with.
in afnetworking can see taskdelegate defined follows:
@interface afurlsessionmanagertaskdelegate : nsobject <nsurlsessiontaskdelegate, nsurlsessiondatadelegate, nsurlsessiondownloaddelegate> @property (nonatomic, weak) afurlsessionmanager *manager; @property (nonatomic, strong) nsmutabledata *mutabledata; @property (nonatomic, strong) nsprogress *progress; @property (nonatomic, copy) nsurl *downloadfileurl; @property (nonatomic, copy) afurlsessiondownloadtaskdidfinishdownloadingblock downloadtaskdidfinishdownloading; @property (nonatomic, copy) afurlsessiontaskcompletionhandler completionhandler; @end @implementation afurlsessionmanagertaskdelegate
and subsequently retrieved follows:
- (afurlsessionmanagertaskdelegate *)delegatefortask:(nsurlsessiontask *)task { nsparameterassert(task); afurlsessionmanagertaskdelegate *delegate = nil; [self.lock lock]; delegate = self.mutabletaskdelegateskeyedbytaskidentifier[@(task.taskidentifier)]; [self.lock unlock]; homecoming delegate; }
see this post more info
objective-c inheritance casting nsurlsession
No comments:
Post a Comment