gpt4 book ai didi

ios - 显示远程通知期间应用崩溃

转载 作者:行者123 更新时间:2023-12-03 17:17:53 26 4
gpt4 key购买 nike

我正在尝试使用Toast显示横幅,如果应用程序在其前台时收到通知。

简单的情况很好,没有任何问题。

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UIView *parentView = [UIApplication sharedApplication].keyWindow.rootViewController.view;
[parentView makeToast:@"toast"];
}

但是,当我尝试显示自己的自定义 View 时,在 EXC_BAD_ACCESS方法上出现了严重的 showToast错误:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UIView *bannerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.topController.view.frame.size.width, 80)];
UIView *parentView = [UIApplication sharedApplication].keyWindow.rootViewController.view;
bannerView.backgroundColor = [UIColor redColor];
[parentView showToast: bannerView duration:3.0 position:CSToastPositionTop completion:nil];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo方法是进行此类行为编程的危险场所吗?对parentView的强引用似乎也不起作用,如何确定哪个对象被过度释放?

最佳答案

您可以直接在appdelegate窗口(位于所有 View 的顶层)上显示Toast,而不是立即获得父 View 。

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{


if (application.applicationState == UIApplicationStateActive)
{
[self.window makeToast:@"This is a piece of toast."];
}
}

关于ios - 显示远程通知期间应用崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35468579/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com