代码之家  ›  专栏  ›  技术社区  ›  winsmith

iPhone应用程序因本地通知而崩溃

  •  0
  • winsmith  · 技术社区  · 15 年前

    这是 奇怪的

    没有控制台输出,我只是得到一个对话框,说“模拟应用程序退出”在iPhone模拟器。在真正的iPhone上,我被甩回跳板。

    - (void)scheduleLocalNotificationsForAlarmsWithNextAlarmAt:(NSDate *)theFireDate ofType:(int)workPlayType {  
    
        BOOL backgroundSupported = NO;
        UIDevice* device = [UIDevice currentDevice];
        if ([device respondsToSelector:@selector(isMultitaskingSupported)])
            backgroundSupported = device.multitaskingSupported;
        if(!backgroundSupported) return;
    
        int work_minutes = [[NSUserDefaults standardUserDefaults] integerForKey:@"work_minutes_preference"];
        int play_minutes = [[NSUserDefaults standardUserDefaults] integerForKey:@"play_minutes_preference"];
    
        int workPlayStatusForNotif = workPlayType;
    
        UILocalNotification *localNotif = [[UILocalNotification alloc] init];
        if (localNotif == nil)
            return;
    
        if (workPlayStatusForNotif == 1) {
            localNotif.alertBody = @"Work";
            localNotif.repeatInterval = work_minutes;
        } else {
            localNotif.alertBody = @"Play";
            localNotif.repeatInterval = play_minutes;
        }
    
        localNotif.fireDate = theFireDate;
        localNotif.timeZone = [NSTimeZone defaultTimeZone];
    
        localNotif.alertAction = NSLocalizedString(@"View Details", nil);
    
        localNotif.soundName = @"ding.caf";
        localNotif.applicationIconBadgeNumber = 0;
    
        [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
        [localNotif release];
    
        // now the other one
        localNotif = [[UILocalNotification alloc] init];
    
        if (localNotif == nil)
            return;
    
        if (workPlayStatusForNotif == 0) {
            localNotif.alertBody = @"Work";
            localNotif.fireDate = [theFireDate dateByAddingTimeInterval:(float)work_minutes*60];
            localNotif.repeatInterval = work_minutes;
        } else {
            localNotif.alertBody = @"Play";
            localNotif.fireDate = [theFireDate dateByAddingTimeInterval:(float)play_minutes*60];
            localNotif.repeatInterval = play_minutes;
        }
        localNotif.timeZone = [NSTimeZone defaultTimeZone];
    
        localNotif.alertAction = NSLocalizedString(@"View Details", nil);
    
        localNotif.soundName = @"ding.caf";
        localNotif.applicationIconBadgeNumber = 0;
    
        [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
        [localNotif release];
    }
    
    3 回复  |  直到 15 年前
        1
  •  1
  •   Ben Zwak    15 年前

    这似乎是一个iOS4.1错误。我有类似的问题,我的应用程序,它曾经与4.0工作。也有人在苹果开发者论坛上报道了类似的问题。等待苹果的回应。

    问候语,

        2
  •  1
  •   Bahtiyar Tamer    15 年前

    剩下的代码看起来没问题。

        3
  •  1
  •   Aamir Ali    15 年前

    是的,这是一个iOS 4.1版本的问题,我也遇到过类似的问题“模拟器崩溃”,但我也经历过另一个问题,那就是:

    我找不到任何解决方法来执行多个本地通知。苹果开发团队必须深入验证本地通知。

    推荐文章