2017-11-06 11 views
6

私のアプリケーションは、バックグラウンドまたは非アクティブモードでローカル通知が機能しません。私は時計で地元の通知を受け取ったことがない。WatchOS App 4.0:ローカル通知をスケジュールする方法

更新: 3分以下ではローカル通知をスケジュールしても問題ありませんが、3分以上経過すると動作しません。どのようにこの問題を解決する?

私の理解によれば、私のコードは以下の通りです。

UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; 
center.delegate = self; 

// Objective-C 
UNMutableNotificationContent *content = [UNMutableNotificationContent new]; 
content.title = [NSString localizedUserNotificationStringForKey:@"Remider!" arguments:nil]; 
content.body = [NSString localizedUserNotificationStringForKey:@"Your watch is out of range" arguments:nil]; 
content.sound = [UNNotificationSound defaultSound]; 

// Time 
// 15 min 
double timer = 15*60; 
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:time 
                           repeats:NO]; 
// Actions 
UNNotificationAction *snoozeAction = [UNNotificationAction actionWithIdentifier:@"Track" 
                      title:@"Track" options:UNNotificationActionOptionForeground]; 

// Objective-C 
UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:@"UYLReminderCategory" 
                      actions:@[snoozeAction] intentIdentifiers:@[] 
                      options:UNNotificationCategoryOptionCustomDismissAction]; 
NSSet *categories = [NSSet setWithObject:category]; 

// Objective-C 
[center setNotificationCategories:categories]; 

// Objective-C 
content.categoryIdentifier = @"UYLReminderCategory"; 

NSString *identifier = [self stringUUID]; 
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier 
                     content:content trigger:trigger]; 

[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { 
    if (error != nil) { 
     NSLog(@"Something went wrong: %@",error); 
    } 
}]; 

提案やアイデアがあれば気に入ってください。

答えて

0

iPhoneがロックされていることを確認してください。通知に関しては、その通知をどこで提供するかについての好みがあります。

iPhoneシミュレータからウォッチアプリを実行し、通知をスケジュールしてiPhoneシミュレータ画面をロックし、ウォッチシミュレータをアクティブにしておきます。その場合、通知がトリガされると時計シミュレータに配信されます。実際のデバイスでテストする場合も同じですSource Link

iphoneと時計の両方がロックされている場合は、iphoneが優先されます。

UPDATE

Notification on Apple Watch

+0

私はこれを知っています。私は実際のデバイスでテストされ、私は腕時計のデバイスにローカル通知を受信しなかった。 –

+0

私は10分間隔でテストし、それは働いた。通知がスケジュールされていることを確認してください。そうであれば、それはどこかで納品されているに違いない。もし時計でなければそれはiphoneでなければならない。 – Muneeba

+0

あなたの仕事に感謝しますが、時計アプリでこの通知が必要です。ウォッチアプリケーションの提案や考え方は? –

関連する問題