Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
升级到iOS 11.3已中断\u弱警报操作_Ios_Objective C_Crash_Uialertcontroller_Uialertaction - Fatal编程技术网

升级到iOS 11.3已中断\u弱警报操作

升级到iOS 11.3已中断\u弱警报操作,ios,objective-c,crash,uialertcontroller,uialertaction,Ios,Objective C,Crash,Uialertcontroller,Uialertaction,昨天我把iphone6s升级到了ios11.3。当我打开应用程序时,它立即崩溃了。我跟踪到以下代码,发现我的“是”UIAlertAction为零 即使在我取出弱声明之后,代码仍会运行并且不会崩溃,但是我的警报不会像以前那样在屏幕上弹出。我到处都在使用这些警报 我的代码是否有问题,或者这是一个合法的11.3 iOS错误? 更新到11.3后,还有其他人发生过类似的崩溃吗? 这段代码已经完美地工作了1.5年了,没有最近的更新 变化 -(void)alertGotoAppSettings:(NSStri

昨天我把iphone6s升级到了ios11.3。当我打开应用程序时,它立即崩溃了。我跟踪到以下代码,发现我的“是”UIAlertAction为零

即使在我取出弱声明之后,代码仍会运行并且不会崩溃,但是我的警报不会像以前那样在屏幕上弹出。我到处都在使用这些警报

我的代码是否有问题,或者这是一个合法的11.3 iOS错误? 更新到11.3后,还有其他人发生过类似的崩溃吗? 这段代码已经完美地工作了1.5年了,没有最近的更新 变化

-(void)alertGotoAppSettings:(NSString*)标题:(NSString*)消息:(UIViewController*)视图
{
UIAlertController*alert=[UIAlertController alertControllerWithTitle:title
信息:msg
首选样式:UIAlertControllerStyleAlert];
UIAlertAction uu弱*是=[UIAlertAction
标题为:LOC的行动(@“是”)
样式:UIAlertActionStyleDefault
处理程序:^(UIAlertAction*操作)
{
//GPS的发射设置
如果(UIApplicationOpenSettingsURLString!=nil){
NSURL*url=[NSURL URLWithString:UIApplicationOpenSettingsURLString];
如果(是IOS\u10\u或更高版本){
[[UIApplication sharedApplication]openURL:url选项:@{}completionHandler:^(布尔成功)
{
}];
}
否则{
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
}
}];
UIAlertAction\uuuu弱*否=[UIAlertAction
诉讼名称:LOC(“否”)
样式:UIAlertActionStyleCancel
处理程序:^(UIAlertAction*操作)
{
dispatch\u async(dispatch\u get\u main\u queue()^{
[警报解除ViewControllerInitiated:是完成:无];
});
}];
[警报添加操作:否];

[alert addAction:yes];无论是
yes
还是
no
都不应该是
\uu-weakAlert
/
strongAlert
模式

弱引用只应在所讨论的对象具有其他显式强引用时使用,但您只是不希望您的代码建立另一个强引用。特别是,当存在强引用循环的风险时,您使用
。但这里不存在这种潜在的强引用循环。坦白说,它很简单在没有其他明确的强引用的情况下,将
与局部变量结合使用是没有意义的

总之,
weak
意味着“当没有强引用剩余时,可以解除分配此对象,并且可以将此特定引用设置为
nil
”。但是在这种情况下,由于您唯一的引用是
weak
引用,因此没有任何强引用。因此,ARC可以自由解除分配它们


所讨论的代码可能在过去就已经运行了(也许ARC在何时释放对象方面更加保守),但在本例中删除这些
引用是正确的。它们没有任何用途,并且使对象的范围不明确。

为什么是
\uu弱
?这是您代码中的一个错误。GC可以立即收集实例,因为没有引用它。我认为弱引用会一直挂起,直到范围结束方法。如果它可以在任何时候消失,它的目的是什么?我的意思是,如果它可以在下一行中删除,那又有什么意义呢?因为超出范围的东西可能包含引用,而弱允许一个人安全地使用某些东西,而不会引起保留周期或影响生命周期。
- (void) alertGotoAppSettings:(NSString *)title :(NSString *)msg :(UIViewController *)view
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title
                                                                    message:msg
                                                             preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction __weak *yes = [UIAlertAction
                         actionWithTitle:LOC(@"Yes")
                         style:UIAlertActionStyleDefault
                         handler:^(UIAlertAction * action)
                         {
                             // Launch Settings for GPS
                             if (UIApplicationOpenSettingsURLString != nil) {
                                 NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
                                 if (IS_IOS_10_OR_LATER) {
                                     [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success)
                                      {
                                      }];
                                 }
                                 else {
                                     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
                                 }
                             }
                         }];

    UIAlertAction __weak *no = [UIAlertAction
                         actionWithTitle:LOC(@"No")
                         style:UIAlertActionStyleCancel
                         handler:^(UIAlertAction * action)
                         {
                             dispatch_async(dispatch_get_main_queue(), ^{
                                 [alert dismissViewControllerAnimated:YES completion:nil];
                             });
                         }];

    [alert addAction:no];
    [alert addAction:yes]; <---- 'yes' is nil here

    UIAlertController __weak *weakAlert = alert;
    dispatch_async(dispatch_get_main_queue(), ^{
        UIAlertController *strongAlert = weakAlert;
        [view presentViewController:strongAlert animated:YES completion:nil];
    });
}