开发者

Unable to simulate invoking applicationDidReceiveMemoryWarning:?

Here is the calling code:

[[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationDidReceiveMemoryWarningNotification
                                                    object:[UIApplication sharedApplication]];

It can not invoke applicationDidReceiveMemoryWarning: from UIApplicationDelegate.

Anythin开发者_开发问答g wrong?


In the simulator, use the menu to trigger a low memory warning.

Unable to simulate invoking applicationDidReceiveMemoryWarning:?


You cannot simulate a memory warning by posting a notification. The UIApplicationDidReceiveMemoryWarningNotification is posted by UIApplication when it receives a memory warning, but it doesn't observe it, and therefore doesn't call your view controllers' didReceiveMemoryWarning: method when you post such a notification manually.

As Rob already pointed out though, you can simulate a memory warning in the iOS simulator by using the "Simulate Memory Warning" menu item.

You could also observe the notification in your view controllers, instead of implementing didReceiveMemoryWarning:, but I wouldn't recommend that, because the behavior of system-supplied view controllers might be different when you fake a memory warning that way.


What should work is using UIApplicationMemoryWarningNotification instead of UIApplicationDidReceiveMemoryWarningNotification:

[[NSNotificationCenter defaultCenter] postNotificationName:@"UIApplicationMemoryWarningNotification"
        object:[UIApplication sharedApplication]];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜