0

私のバックグラウンド メソッドでは、次のように 2 つの通知をスケジュールしました。

- (void)applicationDidEnterBackground:(UIApplication *)application
{
   localNotification = [[UILocalNotification alloc] init]; //Create the localNotification object which is declared in appDelegate.h
    [localNotification setFireDate:[NSDate dateWithTimeIntervalSinceNow:[datePicker countDownDuration]]]; //Set the date when the alert will be launched using the date adding the time the user selected on the timer
    [localNotification setAlertAction:@"Launch"]; //The button's text that launches the application and is shown in the alert
    [localNotification setAlertBody:[alertBodyField text]]; //Set the message in the notification from the textField's text
    [localNotification setHasAction: YES]; //Set that pushing the button will launch the application
    [localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1]; //Set the Application Icon Badge Number of the application's icon to the current Application Icon Badge Number plus 1
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; //Schedule the notification with the system

// * * 通知 2* * *

localNotification2 = [[UILocalNotification alloc] init]; //Create the localNotification object which is declared in appDelegate.h
        [localNotification2 setFireDate:[NSDate dateWithTimeIntervalSinceNow:[datePicker countDownDuration]]]; //Set the date when the alert will be launched using the date adding the time the user selected on the timer
        [localNotification2 setAlertAction:@"Launch"]; //The button's text that launches the application and is shown in the alert
        [localNotification2 setAlertBody:[alertBodyField text]]; //Set the message in the notification from the textField's text
        [localNotification2 setHasAction: YES]; //Set that pushing the button will launch the application
        [localNotification2 setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1]; //Set the Application Icon Badge Number of the application's icon to the current Application Icon Badge Number plus 1
        [[UIApplication sharedApplication] scheduleLocalNotification:localNotification2]; //Schedule the notification with the system

}

通知が来るとうまくいきます。

質問

どの通知が来たかをどのように検出できますdidreceivenotification methodか?? 届いた通知に基づいて別のタスクを実行したいからです。

4

2 に答える 2

1

userInfo辞書を設定できます

localNotification1 = [[UILocalNotification alloc] init]; 
localNotification1.userInfo = @{ "type" : @1 };
...
localNotification2 = [[UILocalNotification alloc] init]; 
localNotification2.userInfo = @{ "type" : @2 };
...
...
于 2013-06-25T10:07:32.167 に答える
0

NSDictionaryのinuserInfoプロパティを設定できますUILocalNotification

だから、あなたはこのようにすることができます...

localNotification1.userInfo = [NSDictionary dictionaryWithObject:@"1" forKey:@"NO"];
localNotification1.userInfo = [NSDictionary dictionaryWithObject:@"2" forKey:@"NO"];

のキー「NO」を比較しますdidReceiveNotification

于 2013-06-25T10:10:20.320 に答える