ios - 多个 UNUserNotifications 未触发
<p><p>我正在设置多个 UNUsernotifications,如下所示,</p>
<pre><code>- (void)viewDidLoad {
;
notifCount = 0;
UNUserNotificationCenter *center = ;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert)
completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (!error) {
NSLog(@"request succeeded!");
;
}
}];
}
</code></pre>
<p>在 <code>set10Notif</code> 方法中,我设置了多个(8 个用于测试)通知,时间距当前时间 10 秒。</p>
<pre><code>-(void) set10Notif
{
notifCount = notifCount+1;
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0") && notifCount < 10)
{
// create actions
NSCalendar *calendar = [ initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
];
NSDate *fireD = [ dateByAddingTimeInterval:notifCount*10];
NSString *fireStr = ;
NSDateComponents *components = ;
UNMutableNotificationContent *objNotificationContent = [ init];
objNotificationContent.title = ;
objNotificationContent.body = [NSString localizedUserNotificationStringForKey:fireStr
arguments:nil];
objNotificationContent.sound = ;
UNCalendarNotificationTrigger *trigger = ;
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"Prayer"
content:objNotificationContent trigger:trigger];
UNUserNotificationCenter *userCenter = ;
[userCenter addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (!error) {
NSLog(@"Local Notification succeeded");
}
else {
NSLog(@"Local Notification failed");
}
;
}];
#endif
}
}
</code></pre>
<p><strong>所有本地通知均已设置。但是设备中只有一个通知被触发,这是最后一个。</strong></p>
<p>为什么不能触发多个通知?
我做错了什么?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>为每个通知提供不同的“requestWithIdentifier”和“时间延迟”并尝试,可能对您有用。 </p></p>
<p style="font-size: 20px;">关于ios - 多个 UNUserNotifications 未触发,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/40277590/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/40277590/
</a>
</p>
页:
[1]