简体   繁体   English

通过推送通知Objective C iOS从“终止”状态打开时,应用崩溃

[英]App crash when open from Kill state through Push notification Objective C iOS

My app working fine when app is in background and open it by clicking on Push Notification. 当我的应用程序在后台运行时,我的应用程序运行正常,并通过单击“推送通知”将其打开。 But if I terminate app and open it through push notification then app crash. 但是,如果我终止应用程序并通过推送通知将其打开,则应用程序将崩溃。 I also integrate Crashlytics. 我还集成了Crashlytics。 Here is attached photo & code. 这是随附的照片和代码。 App crash only in one type of notification.It is not data parsing issue. 应用程序仅在一种通知中崩溃,这不是数据解析问题。

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert)
                          completionHandler:^(BOOL granted, NSError * _Nullable error) {
                              if (!error) {
                                  NSLog(@"request authorization succeeded!");
                                  //[self showAlert];
                              }
                          }];




// Branch Intigration
    Branch *branch = [Branch getInstance];

//    if is debug
//    [[Branch getInstance] setDebug];


    [branch initSessionWithLaunchOptions:launchOptions andRegisterDeepLinkHandler:^(NSDictionary *params, NSError *error) {
        if (!error && params) {
            DecisionController * mainVC = [[DecisionController alloc] init];
            [mainVC viewDidLoad];
            // params are the deep linked params associated with the link that the user clicked -> was re-directed to this app
            // params will be empty if no data found
            // ... insert custom logic here ...
            NSString * non_branch_link  = [params objectForKey:@"+clicked_branch_link"];
            if ([[params objectForKey:@"+clicked_branch_link"] boolValue]) {
                NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
                [nc postNotificationName:@"DeepLinkNotification" object:self userInfo:params];
            }
            NSLog(@"params: %@", params.description);
        }
    }];

    // MAGICAL RECORD Intigration
    [MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:@"EmergencMeDatabase.sqlite"];
//    [Fabric with:@[[branch class]]];
    NSLog(@"magical record path to SQLite base %@", [NSPersistentStore MR_defaultLocalStoreUrl]);
    [Fabric with:@[[Crashlytics class]]];

    [SharedRenderer setValue:@"NO" key:isForRedar];
    [[NSUserDefaults standardUserDefaults] setFloat:0 forKey:@"lastnotificationminute"];
    [[FBSDKApplicationDelegate sharedInstance] application:application
                             didFinishLaunchingWithOptions:launchOptions];
    [MPNotificationView registerNibNameOrClass:@"CustomNotificationView"
                        forNotificationsOfType:@"Custom"];
    [self registerForRemoteNotifications];
    [SharedRenderer sharedInstance].retryCount = 0;
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"generatenotification"];
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"FirstSubscribe"];
    mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone"
                                               bundle: nil];
    if (launchOptions[UIApplicationLaunchOptionsLocationKey]) {

        [self startLocationManager:@""];
    }
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
    {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        [SharedRenderer setValue:@"0" key:@"alldatafetched"];
        [SharedRenderer setValue:@"" key:@"currentchannel"];
        NSMutableArray* alerts = [[NSMutableArray alloc] init];
        NSData* alertsData=[NSKeyedArchiver archivedDataWithRootObject:alerts];
        [[NSUserDefaults standardUserDefaults] setObject:alertsData forKey:@"nonreasonalerts"];
        NSMutableArray* receivedAlerts = [[NSMutableArray alloc] init];
        NSData* receivedAlertsData=[NSKeyedArchiver archivedDataWithRootObject:receivedAlerts];
        [[NSUserDefaults standardUserDefaults] setObject:receivedAlertsData forKey:@"receivedalerts"];
        NSMutableArray* myAlerts = [[NSMutableArray alloc] init];
        NSData* myAlertsData=[NSKeyedArchiver archivedDataWithRootObject:myAlerts];
        [[NSUserDefaults standardUserDefaults] setObject:myAlertsData forKey:@"myalerts"];
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"OB"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    if (![[SharedRenderer getValueFor:@"isLogin"] boolValue])
    {
        navigationController = [mainStoryboard instantiateViewControllerWithIdentifier:@"loginVC"];
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"showhomealert"];
    }
    else
    {
        if ([[SharedRenderer getValueFor:@"family_id"] isEqualToString:@""] || [[SharedRenderer getValueFor:@"alldatafetched"] isEqualToString:@"0"])
        {
            navigationController = [mainStoryboard instantiateViewControllerWithIdentifier:@"Smarticestep1"];
        }
        else
        {
            navigationController = [mainStoryboard instantiateViewControllerWithIdentifier:@"homenav"];
            [self activatedeacAlertTimer];
            [self activatePendingAlertTimer];
            [self checkFor_AlertDeactivation];
            [self fetchInvitationCount];
            // Mark by Mian:
            //            [self updatePSAlertTable];
        }
    }
    [self.window setRootViewController: navigationController];
    [self.window makeKeyAndVisible];
    LeftMenuViewController *leftMenu = (LeftMenuViewController*)[mainStoryboard
                                                                 instantiateViewControllerWithIdentifier: @"LeftMenuViewController"];
    RightMenuViewController *rightMenu = (RightMenuViewController*)[mainStoryboard
                                                                    instantiateViewControllerWithIdentifier: @"RightMenuViewController"];
    [SlideNavigationController sharedInstance].rightMenu = rightMenu;
    [SlideNavigationController sharedInstance].leftMenu = leftMenu;
    [SlideNavigationController sharedInstance].menuRevealAnimationDuration = .4;

    // Creating a custom bar button for right menu
    UIButton *button  = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    [button setImage:[UIImage imageNamed:@"gear"] forState:UIControlStateNormal];
    [button addTarget:[SlideNavigationController sharedInstance] action:@selector(toggleRightMenu) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    [SlideNavigationController sharedInstance].rightBarButtonItem = rightBarButtonItem;
    [[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidClose object:nil queue:nil usingBlock:^(NSNotification *note)
     {
         //         NSString *menu = note.userInfo[@"menu"];
     }];

    [[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidOpen object:nil queue:nil usingBlock:^(NSNotification *note)
     {
         //         NSString *menu = note.userInfo[@"menu"];
     }];

    [[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidReveal object:nil queue:nil usingBlock:^(NSNotification *note)
     {
         //         NSString *menu = note.userInfo[@"menu"];
     }];
    [self ConnectPusher];
    if ([[SharedRenderer getValueFor:@"isLogin"] boolValue]){
        [self checkFor_AlertDeactivation];
        [self removePastAlert];
        [self deactivateAlert];
        [self goOnline_Offline:@"1"];
    }
    [self showAlert:launchOptions];
    return YES;
}

在此处输入图片说明

问题是,您会从didFinishLaunchingWithOptions方法的launchOptions中获取打开应用程序的通知,并在打开应用程序时传递给处理该函数的相同功能,并执行push / present操作,因为尚未设置Windows的根视图控制器,导致应用程序崩溃,因此请延迟到应用激活之前

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过“推送通知”从“终止”状态打开应用程序时,iOS Web View App崩溃 - iOS Web View App crashed when Application is open from kill state through Push Notification 在iOS目标C中应用处于活动状态时如何获取推送通知? - How to get push notification when app is in active state in ios objective c? flutter 通知不会出现在 ios 当应用程序正在杀死 state 但当我们打开应用程序时通知即将到来 - flutter notification is not coming in ios when app is on kill state but when we open the app notification is coming 当应用未处于运行状态iOS时通过通知横幅打开应用 - Open app through notification banner when app is not running state iOS 从推送通知 IOS 打开应用程序时打开特定的 ViewController - Open specific ViewController when open app from push notification IOS 处于“未运行”状态时在iOS应用中推送通知 - Push notification in iOS app when “Not running” state Objective-C IOS 7推送通知在应用程序未运行时保存数据? - Objective-C IOS 7 push notification save data when app not running? iOS:Objective -C如何在应用程序处于后台模式时更改推送通知声音有效负载? - iOS:Objective -C How to change push notification sound payload when app in background mode? ios-在应用程序处于活动状态时打开推送通知时,它会导致崩溃 - ios - when opening a push notification while the app is active, it cases a crash App在前景上并收到推送通知消息(IOS)时发生钛合金崩溃 - Titanium Crash when App is on Foreground and receives a Push Notification message (IOS)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM