1

私の質問は、私のアプリケーションについて持っているこの通知です。

音楽アプリのリマインダー通知を使用しているので、番組を再生する 2 時間前に通知を受け取ることができます。この同様のコードを以前にテストしましたが、 NSString date ではなく整数コンポーネントを使用して、機能しました。ただし、この特定のインスタンスでは文字列を使用する必要があります。

私には、すべてが機能しているように見えます。シングルトン内にある NSLog は正しい情報を出力します。EG =

NSLog(@"Notification will be shown on: 2014-07-18 11:03:00 +0000)

では、なぜ通知が届かないのでしょうか。私はしばらく努力してきましたが、一日中障害物にぶつかっていました。いくつかの支援をいただければ幸いです。

ありがとうございました!

- (void)scheduleNotificationForDate:(NSDate *)date {

    // Here we cancel all previously scheduled notifications
    [[UIApplication sharedApplication] cancelAllLocalNotifications];

    UILocalNotification *localNotification = [[UILocalNotification alloc] init];

    localNotification.fireDate = date;
    NSLog(@"Notification will be shown on: %@",localNotification.fireDate);

    localNotification.timeZone = [NSTimeZone defaultTimeZone];
    localNotification.alertBody = [NSString stringWithFormat:@"Aurora Radio plays in 2 hours!"];
    localNotification.alertAction = NSLocalizedString(@"View details", nil);

    /* Here we set notification sound and badge on the app's icon "-1"
       means that number indicator on the badge will be decreased by one
       - so there will be no badge on the icon 
    */
    localNotification.soundName = UILocalNotificationDefaultSoundName;
    localNotification.applicationIconBadgeNumber = 1;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}

IBAction=

-(IBAction)setReminder {

    // Setting all the information about our date
    NSString * dateString = @"2014-07-18 11:03:00";

    NSDateFormatter *dateFormatter = [NSDateFormatter new];
    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

    NSDate *myNewDate = [dateFormatter dateFromString:dateString];

    [self scheduleNotificationForDate:myNewDate];

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Aurora Radio"
                                                message:@"Alarm has been set two hours prior to performance!"
                                               delegate:self
                                      cancelButtonTitle:@"Sounds good bros, see you later."
                                      otherButtonTitles:nil];
    [alert show];
}
4

0 に答える 0