私のアプリは将来のために複数のUNNotificationRequestをスケジュールします。各要求には一意の識別子があります。 repeatはNOに設定されているため、UNCalanderNotificationTriggerでリピートすることはできません。むしろ、各要求は異なる将来のカレンダー日付に設定されますが、それらはすべてシリアルで、本質的に同時に要求されます。各トリガーは、次のメソッドに渡される間隔(NSTimeInterval)によって設定されます。アプリケーションがバックグラウンドまたはフォアグラウンドのいずれかにある場合は、後でUNNotificationCenterデリゲート(appDelegate)でリクエストが受信されません。 Appleの開発者向けドキュメントには関連する例はありません。完了ハンドラで完了をチェックする必要があるのかどうか疑問に思っています(私のコードにはwithCompletionHandler:nilがありますが、これはAppleの例に示されています)。未解決のUNNotificationRequestが複数存在することはありますか?
0
A
答えて
0
答えは「はい」です。複数の未解決のNSNotificationRequestが存在する可能性があります。次のコードが動作します:
-(UNNotificationRequest *)triggerNotifications: (NSString *)identifier : (NSTimeInterval) interval{
// Note: identifier must be unique or else each new request causes all others to be cancelled.
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init];
content.title = NSLocalizedString(@"Timer expired", nil);
content.body = NSLocalizedString(@"Touch to continue", nil);
NSUserDefaults *storage = [NSUserDefaults standardUserDefaults];
BOOL sound = [storage boolForKey:@"sound permission granted"];
if(sound){
if([self.selectedSound isEqual:NSLocalizedString(kselectedSoundKeyDoorBell, nil)]){
content.sound = [UNNotificationSound soundNamed:@"doorbell.caf"];
}else if ([self.selectedSound isEqual:NSLocalizedString(kselectedSoundKeySystemDefault, nil)]){
content.sound = [UNNotificationSound defaultSound];
}else if ([self.selectedSound isEqual:NSLocalizedString(kselectedSoundKeyElectronicChime, nil)]){
content.sound = [UNNotificationSound soundNamed:@"electronic_chime.caf"];
}else{
if([self.selectedSound isEqual:NSLocalizedString(kselectedSoundKeyComputer, nil)]){
content.sound = [UNNotificationSound soundNamed:@"Computer.caf"];
}
}
}
content.categoryIdentifier = @"com.nelsoncapes.localNotification";
NSDate *today = [NSDate date];
NSDate *fireDate = [today dateByAddingTimeInterval:interval];
// first extract the various components of the date
NSCalendar *calendar = [NSCalendar currentCalendar];
NSInteger year = [calendar component:NSCalendarUnitYear fromDate:fireDate];
NSInteger month = [calendar component:NSCalendarUnitMonth fromDate:fireDate];
NSInteger day = [calendar component:NSCalendarUnitDay fromDate:fireDate];
NSInteger hour = [calendar component:NSCalendarUnitHour fromDate:fireDate];
NSInteger minute = [calendar component:NSCalendarUnitMinute fromDate:fireDate];
NSDateComponents *components = [[NSDateComponents alloc]init];
components.year = year;
components.month = month;
components.day = day;
components.hour = hour;
components.minute = minute;
// construct a calendarnotification trigger and add it to the system
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:NO];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier: identifier content:content trigger:trigger];
[center addNotificationRequest:request withCompletionHandler:^(NSError *error){
if(error){
NSLog(@"error on trigger notification %@", error);
}
}];
return request;
}
関連する問題
- 1. VHDL未解決の信号 'i2c_rx_data'に複数のソースがあります
- 2. sbt-android-plugin 0.6.0-SNAPSHOTに未解決の依存関係がありますか?
- 3. Swift Parse - このクエリには未解決のネットワーク接続エラーがあります
- 4. 1つのElasticBeanstalk環境に複数のAutoScalingグループが存在することはありますか?
- 5. 未解決のプロミス拒否未定義は関数ではありません
- 6. Laravel複数のget()リクエスト - より良い解決策がありますか?
- 7. SQL 71501に未解決のアセンブリ参照があります
- 8. 複数のリクエストを同時に解決する方法はありますか?
- 9. イメージが存在するか複数のバックグラウンドイメージがあるか
- 10. gTLDの直後にサーバーが存在することはありますか?
- 11. このエラーを解決する必要があります
- 12. JavaScriptの複数行の文字列にJavascript ILLEGALトークンエラーがあります。これを解決するには?
- 13. 明確に存在する未解決のOpenSSLシンボルを参照するエラー?
- 14. 「未解決の依存関係があります...」というメッセージが表示されない
- 15. 関数ポインタを渡すときに未解決の外部シンボルがある
- 16. ZeroMQは未解決のメッセージの数をカウントできますか?
- 17. サービスワーカーが複数いる場合、Navigator.serviceWorkerはどのように解決しますか?複数のサービス労働者が存在する場合
- 18. ネストしたセットに子オブジェクトが重複していたり、複数のparent_id/root /ノードが存在することはありますか?
- 19. plotly scala sbt未解決の依存関係が見つかりません
- 20. コレクションにJavaのイテレータが複数あることはありますか?
- 21. Java 8でJAVA FATAL ERRORを解決する解決策はありますか?
- 22. 未定義の参照(nmは関数が存在すると言います)
- 23. 複数のディレクトリで錆コードを整理するときに未解決のインポート
- 24. 'myLogin'が現在のコンテンツに存在しないことを修正する方法はありますか?
- 25. iPhoneアプリケーションでUIApplicationDelegateプロトコルに準拠する複数のクラスが存在する可能性はありますか?
- 26. SBT:。SPARK2.0 *:SCALA:未解決の依存関係がorg.glassfish.hk2とjavax.validation
- 27. このhyperledger curlコマンドのエラーを解決する方法はありますか?
- 28. Hortonworks shc未解決の依存関係
- 29. 未解決の依存関係[クラスサービス層]
- 30. SBT未解決の依存関係2.0.2