美文网首页
2018-06-25 饿了么iOS隐私政策条款不同意并退出App

2018-06-25 饿了么iOS隐私政策条款不同意并退出App

作者: HaloMartin | 来源:发表于2018-06-25 18:16 被阅读0次

印象里,iOS除了使用Home键,并不能主动退出,今天中午订餐的时候,打开了许久没用的饿了么,意外发现,饿了么有不同意并退出的功能,百度尝试了一下,只是很简单的一段代码而已,效果和数据安全且不论,但是确实可以实现退出App。
退出App的三种方法,exit(1)、abort()、assert(0)
源码在底部:

1.exit(1)

附加了关闭打开文件与返回状态码给执行环境,并调用你用atexit注册的返回函数
iOS终止函数exit
调用exit会让用户感觉程序崩溃了,不会有按Home键返回时的平滑过渡和动画效果;另外,使用exit可能会丢失数据,因为调用exit并不会调用-applicationWillTerminate:方法和UIApplicationDelegate方法

2.abort()

解除进程对SIGABRT信号的阻止,然后向调用进程发送该信号,abort()可以导致进程的异常终止,除非SIGABRT信号被处理,可以通过NSSetUncaughtExceptionHandler来捕捉,从而可以做到从容的退出App,参考资料如下:RunLoop总结:RunLoop的应用场景(五)阻止App崩溃一次

捕捉并处理异常效果图

3.assert(0)

Assert断言

当程序检查到断言条件为false时,触发断言,而后程序崩溃,可在日志中读到相关的过程,在正式发布的Release版中,一般都是会禁用断言功能的;
assert(0)同样可以用捕捉处理abort()的方式进行捕捉,因为assert最终还是会调用abort()产生SIGABRT信号来终止App

总结

OC并不提供正常退出iOSApp的API,上面三种方式虽然可以退出App,但不符合苹果一贯的友好风格,所以也是有可能上架悲剧。
源码:

//
//  AppExitTestViewController.m
//  Modulator
//
//  Created by M君 on 25/06/2018.
//  Copyright © 2018 huihaiweishi. All rights reserved.
//

#import "AppExitTestViewController.h"

typedef NS_ENUM(NSUInteger, AppExitTestTag) {
    AppExitTestTag_Exit = 100,
    AppExitTestTag_Abort,
    AppExitTestTag_Assert,
};

@interface AppExitTestViewController ()


@end

@implementation AppExitTestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor lightGrayColor];
    //
    UIButton *exitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    exitBtn.frame = CGRectMake(0, 0, 100, 60);
    exitBtn.layer.borderWidth = 1.0;
    exitBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    exitBtn.tag = AppExitTestTag_Exit;
    exitBtn.backgroundColor = [UIColor lightGrayColor];
    [exitBtn setTitle:@"Exit" forState:UIControlStateNormal];
    [exitBtn addTarget:self action:@selector(onAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:exitBtn];
    //
    UIButton *abortBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    abortBtn.frame = CGRectMake(0, 0, 100, 60);
    abortBtn.layer.borderWidth = 1.0;
    abortBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    abortBtn.tag = AppExitTestTag_Abort;
    abortBtn.backgroundColor = [UIColor lightGrayColor];
    [abortBtn setTitle:@"Abort" forState:UIControlStateNormal];
    [abortBtn addTarget:self action:@selector(onAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:abortBtn];
    //
    UIButton *assertBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    assertBtn.frame = CGRectMake(0, 0, 100, 60);
    assertBtn.layer.borderWidth = 1.0;
    assertBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    assertBtn.tag = AppExitTestTag_Assert;
    assertBtn.backgroundColor = [UIColor lightGrayColor];
    [assertBtn setTitle:@"Assert" forState:UIControlStateNormal];
    [assertBtn addTarget:self action:@selector(onAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:assertBtn];
    //
    abortBtn.center = self.view.center;
    exitBtn.center = CGPointMake(abortBtn.centerX, abortBtn.top - exitBtn.height/2 - 10);
    assertBtn.center = CGPointMake(abortBtn.centerX, abortBtn.bottom + exitBtn.height/2 + 10);
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - action
- (void)onAction:(UIButton *)btn
{
    NSString *title = @"Terminate the App";
    NSString *message = [NSString stringWithFormat:@"Will Terminate the App with Button: %@",btn.titleLabel.text];
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:nil]];
    [alertController addAction:[UIAlertAction actionWithTitle:@"Confirm" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        AppExitTestTag tag = (AppExitTestTag)btn.tag;
        switch (tag) {
            case AppExitTestTag_Exit:
                exit(1);
                break;
            case AppExitTestTag_Abort:
                abort();
                break;
            case AppExitTestTag_Assert:
                assert(0);
                break;
            default:
                break;
        }
    }]];
    [self presentViewController:alertController animated:YES completion:nil];
}

@end

相关文章

  • 2018-06-25 饿了么iOS隐私政策条款不同意并退出App

    印象里,iOS除了使用Home键,并不能主动退出,今天中午订餐的时候,打开了许久没用的饿了么,意外发现,饿了么有不...

  • 隐私政策

    我们不会收集用户的任何信息,本地也没做缓存信息。 隐私政策条款 使用本APP即表示您同意此隐私政策的条款和条件。如...

  • 承德在线隐私政策

    iOS隐私政策 * 《承德在线》隐私政策 承德在线APP尊重并保护所有使用服务用户的个人隐私权。为了给您提供更准确...

  • App 隐私政策

    本 App 尊重并保护所有使用服务用户的个人隐私权。使用本 App 即表示您同意此隐私政策的条款和条件。如果您不同...

  • 隐私政策

    我们不会收集用户的任何信息,快递查询记录只保存在本地。 隐私政策条款 使用本APP即表示您同意此隐私政策的条款和条...

  • 《延禧浮生记》手游用户协议、用户隐私政策条款

    《延禧浮生记》手游用户协议、用户隐私政策条款 重要须知: 一、用户隐私权政策条款《延禧浮生记》尊重并保护所有使用...

  • 卡片记

    联系我们 邮箱:cedar_xi@qq.com 隐私政策与使用条款 1.隐私政策 本应用尊重并保护所有使用服务用户...

  • iOS 回到应用桌面

    iOS现在越来越重视隐私了,在App启动的时候,需要用户的查看隐私条款并同意后才能初始化第三方库,否则就要退出Ap...

  • 产品隐私政策与使用条款

    以下为小日常、青子记账、布谷番茄的隐私政策与使用条款。 隐私政策 本应用尊重并保护所有使用服务用户的个人隐私权。为...

  • 隐私政策

    我们不会收集用户的任何信息,上海公交收藏的路线,只保存在本地。 隐私政策条款 使用本APP即表示您同意此隐私政策的...

网友评论

      本文标题:2018-06-25 饿了么iOS隐私政策条款不同意并退出App

      本文链接:https://www.haomeiwen.com/subject/dpryyftx.html