can't receive a notification after posting inside connectionDidFinishLoading:, NSURLConnection delegate method

白昼怎懂夜的黑 提交于 2020-01-16 11:59:10

问题


I can't receive a notification with this:

a class for doing NSURLConnection async stuff

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

    NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:_receivedData, @"receivedData", nil];
    [[NSNotificationCenter defaultCenter] postNotificationName:kWebServiceURLTemperaturaMaximaKMLNotitificationName object:self userInfo:userInfo];

}

another class observing the notification:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceivedCompleteData:) name:kWebServiceURLTemperaturaMaximaKMLNotitificationName object:self];

any thoughts?


回答1:


Error is here:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceivedCompleteData:) name:kWebServiceURLTemperaturaMaximaKMLNotitificationName object:self];

This means that notification center will send notification named name:kWebServiceURLTemperaturaMaximaKMLNotitificationName to self that is also generated by self. You should replace object:self with object:nil (to receive any notification named name:kWebServiceURLTemperaturaMaximaKMLNotitificationName) or with object that is actually sending the notification.



来源:https://stackoverflow.com/questions/8188633/cant-receive-a-notification-after-posting-inside-connectiondidfinishloading-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!