开发者社区 问答 正文

当从后台移除并尝试打开时,反应本机iOS应用程序崩溃

我已经创建了Reaction本机IOS应用程序。在我的应用程序中,一切都很好,我也处理了推送通知。为此,我使用了以下代码。它管理我的应用前景,后台两种状态。但是当我从后台删除我的应用程序并尝试打开它时。它在飞溅屏幕后崩溃了。即使我删除了这个推送通知代码,但我仍然无法打开我的应用程序,它总是崩溃。

async createNotificationListenersIos() {

    console.log("createNotificationListenersIOs ");

    /* Triggered when a particular notification has been received in foreground */
   const channel = new firebase.notifications.Android.Channel('test-channel', 'Test Channel', firebase.notifications.Android.Importance.Max)
   .setDescription('My apps test channel');

 // Create the channel
 firebase.notifications().android.createChannel(channel);
 this.notificationListener = firebase.notifications().onNotification((notification) => {

  console.log(" notification is === 81 ", notification);

   notification
     .android.setChannelId('test-channel')
     .android.setSmallIcon('ic_launcher');
   firebase.notifications()
     .displayNotification(notification);

     this.checkForData(notification);

 });

 /*
 * If your app is in background, you can listen for when a notification is clicked / tapped / opened as follows: */

 this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen) => {
   console.log(" notification is === 99 =======", notificationOpen.notification);
   this.checkForData(notificationOpen.notification);
 });

 /*
 * If your app is closed, you can check if it was opened by a notification being clicked / tapped / opened as follows:
*/
/*
firebase.notifications().getInitialNotification()
      .then((notificationOpen: NotificationOpen) => {
        if (notificationOpen) {

            console.log(" 45 ===== ", notificationOpen);
          // App was opened by a notification
          // Get the action triggered by the notification being opened
          const action = notificationOpen.action;
          // Get information about the notification that was opened
          const notification: Notification = notificationOpen.notification;  

          if (notification) {

            // console.log("+================= notificationOpen ", notification, "===========");
             // App was opened by a notification
             // Get the action triggered by the notification being opened
            // const action = notificationOpen.action;
             // Get information about the notification that was opened

             console.log("^^^^^^^^^^^^^^^^^^",notification._notification);
            this.checkForData(notification._notification)
         }
        }
      });  
      */
}

  checkForData (notification){
    if (notification._data) {

        if(notification._data.type){
            if ( notification._data.type.toUpperCase() !== wordConstants.CONST_ADMIN) {
              return;
            }
          }

          console.log("69 ^^^^^^^^^^^^^^^^^^",notification._data.status);

        let notificationStatus = notification._data.status;
        console.log(" notification status ====", notificationStatus.toUpperCase());

        if(notificationStatus.toUpperCase() === wordConstants.CONST_APPROVE){

            this.props.navigation.navigate('LoginProgress', { status: wordConstants.CONST_CONFIRM, userData: {} });
        }else{
            this.props.navigation.navigate('LoginProgress', { status: wordConstants.CONST_FAILED, userData: {} });
        }
    } else {

    }
  }

Can anyone help me.
Thanks

展开
收起
游客5akardh5cojhg 2019-12-14 18:09:18 443 分享 版权
阿里云 AI 助理回答

遇到应用程序在从后台恢复时崩溃的问题,可能的原因有很多,包括但不限于内存管理问题、初始化错误、依赖项未正确配置等。根据你的描述,你已经尝试移除了推送通知相关的代码,但问题依旧存在,这表明问题可能并不直接与推送通知相关,而是其他部分的代码或应用配置导致的。

以下是一些排查和解决此类问题的建议:

  1. 查看崩溃日志:要准确地定位问题,首先需要查看崩溃时的日志输出。对于iOS应用,你可以通过Xcode的Organizer窗口中的"Crashes"标签或者设备日志来获取崩溃日志。这些日志通常会包含崩溃发生时的堆栈跟踪,这对于诊断问题至关重要。

  2. 确保App Delegate配置正确:检查你的AppDelegate.mAppDelegate.swift文件中有关应用生命周期的方法(如application(_:didFinishLaunchingWithOptions:)applicationWillResignActive(_:)applicationDidEnterBackground(_:)applicationWillEnterForeground(_:)applicationDidBecomeActive(_:)以及处理推送通知的相关方法)是否正确实现且没有遗漏可能导致崩溃的逻辑。

  3. 清理并重建项目:有时候,残留的构建产物或缓存可能会导致问题。尝试清理项目(Xcode中选择Product > Clean Build Folder),然后重新构建并运行应用。

  4. 检查第三方库集成:确认所有使用的第三方库(如Firebase)都已正确集成并且版本兼容。有时,库之间的版本不兼容或集成方式不当也会引起崩溃。查看这些库的官方文档,确保遵循了最新的集成指南。

  5. 逐步调试:如果崩溃发生在应用启动阶段,可以尝试逐步注释掉AppDelegate中的初始化代码,特别是那些在应用启动时执行的逻辑,以确定是哪一部分代码导致的崩溃。

  6. 资源和内存使用情况:检查应用是否有内存泄漏或是大量消耗资源的情况,这可以通过Xcode的Instruments工具来分析。

  7. Splash Screen逻辑:由于你提到应用在飞溅屏幕后崩溃,检查飞溅屏幕背后的初始化逻辑是否存在潜在问题,比如试图访问尚未初始化的对象、调用空指针等。

  8. React Native特定问题:如果你的应用是基于React Native开发的,确保React Native桥接和原生模块之间交互的代码没有问题。有时候,JavaScript线程和原生线程之间的通信问题也可能导致应用崩溃。

通过上述步骤,你应该能够逐步缩小问题范围并找到解决方案。记得每次修改后都要进行测试,以便快速定位到问题所在。

有帮助
无帮助
AI 助理回答生成答案可能存在不准确,仅供参考
0 条回答
写回答
取消 提交回答
问答分类:
问答地址: