iOS开发-App应用崩溃卡顿分析

App崩溃问题

app经常会遇见崩溃问题,比如下

  • 数据越界
  • 多线程操作同一指针,当指针为空时崩溃
  • 野指针问题
  • KVO问题
  • NSNotification线程问题

以及不可捕获的崩溃问题:

  • 后台任务超时
  • App超过系统限制的内存大小被杀死
  • 主线程卡顿被杀死

可捕获的崩溃信息收集

对于可以捕获的崩溃问题,我们可以通过崩溃日志分析,例如PLCrashReporterbugly这些三方崩溃分析工具。


PLCrashReporter实现

在崩溃日志中,Exception信息头部经常有
Exception Type: EXC_CRASH (SIGABRT)

常见的崩溃信息

SIGABRT就代表着一种崩溃信息,类似还有SIGSEGVSIGBUS

PLCrashReporter 通过注册这些崩溃signalHandler回调就可以获得崩溃信息。

PLCrashReporter 源码中

/**
 * Register a new signal @a callback for @a signo.
 *
 * @param signo The signal for which a signal handler should be registered. Note that multiple callbacks may be registered
 * for a single signal, with chaining handled appropriately by the receiver. If multiple callbacks are registered, they may
 * <em>optionally</em> forward the signal to the next callback (and the original signal handler, if any was registered) via PLCrashSignalHandlerForward.
 * @param callback Callback to be issued upon receipt of a signal. The callback will execute on the crashed thread.
 * @param context Context to be passed to the callback. May be NULL.
 * @param outError A pointer to an NSError object variable. If an error occurs, this pointer will contain an error object indicating why
 * the signal handlers could not be registered. If no error occurs, this parameter will be left unmodified. You may specify
 * NULL for this parameter, and no error information will be provided.
 *
 * @warning Once registered, a callback may not be deregistered. This restriction may be removed in a future release.
 * @warning Callers must ensure that the PLCrashSignalHandler instance is not released and deallocated while callbacks remain active; in
 * a future release, this may result in the callbacks also being deregistered.
 */
- (BOOL) registerHandlerForSignal: (int) signo
                         callback: (PLCrashSignalHandlerCallbackFunc) callback
                          context: (void *) context
                            error: (NSError **) outError
{
   
    /* Register the actual signal handler, if necessary */
    if (![self registerHandlerWithSignal: signo error: outError])
        return NO;
    
    /* Add the new callback to the shared state list. */
    plcrash_signal_user_callback reg = {
   
        .callback = callback,
        .context = context
    };
    shared_handler_context.callbacks.nasync_prepend(reg);
    
    return YES;
}

可以查看 registerHandlerWithSignal 来查看实现。

PLCrashReporter 将这些崩溃堆栈信息存储后,App就崩溃了,等待下次重启时,就可以取到这些日志,进行上传分析。

系统接口

系统函数的优点在于性能好,但是只能获取简单的信息,无法通过dSYM文件来了解是哪行代码出的问题。

SIGABRT--程序中止命令中止信号
SIGALRM--程序超时信号
SIGFPE--程序浮点异常信号
SIGILL--程序非法指令信号
SIGHUP--程序终端中止信号
SIGINT--程序键盘中断信号
SIGKILL--程序结束接收中止信号
SIGTERM--程序kill中止信号
SIGSTOP--程序键盘中止信号
SIGSEGV--程序无效内存中止信号
SIGBUS--程序内存字节未对齐中止信号
SIGPIPE--程序Socket发送失败中止信号
void InstallSignalHandler(void)
{
   
    signal(SIGHUP, SignalExceptionHandler);
    signal(SIGINT, SignalExceptionHandler);
    signal(SIGQUIT
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iOS开发中,支付是一个非常重要的功能。在开发支付时,需要考虑到支付流程、支付方式、支付安全等方面的内容。以下是一些开发支付的要点: 1. 集成支付SDK iOS开发中,一般使用第三方支付SDK来实现支付功能。常见的支付SDK包括:支付宝SDK、微信支付SDK、银联支付SDK等。在使用SDK前,需要先注册开发者账号,并获取相应的API Key和App ID等信息。 2. 支付流程 支付流程一般包括以下几个步骤: - 用户选择支付方式; - 向支付平台发起支付请求; - 用户输入支付密码; - 支付平台返回支付结果; - 应用根据支付结果进行相应的处理。 3. 支付安全 支付安全是非常重要的。在开发中,需要考虑到以下方面: - 用户信息的安全保护:包括用户的账号、密码、支付信息等; - 支付数据的安全保护:对于涉及到支付的数据,需要采用加密算法进行保护,避免被非法攻击者窃取; - 安全审计:需要对支付过程中的各个环节进行安全审计,及时发现并修复漏洞。 4. 支付方式 在iOS开发中,常见的支付方式包括: - 支付宝支付:支持PC端、移动端、扫码支付等多种支付方式; - 微信支付:支持微信内支付、H5支付、APP支付等多种支付方式; - 苹果支付:支持应用内购买,用户可以直接使用Apple ID进行支付。 需要根据应用的实际情况,选择适合的支付方式。 总之,开发支付需要考虑到多个方面的内容,包括支付流程、支付方式、支付安全等,需要仔细规划和实现,以保证支付功能的正常运作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值