gpt4 book ai didi

ios - 我可以在 WatchOS 2 模拟器上测试本地通知吗?

转载 作者:行者123 更新时间:2023-11-28 21:32:40 25 4
gpt4 key购买 nike

我在谷歌上搜索了很多东西,想找到在 WatchOS 模拟器上检查本地通知的方法,因为我没有 iWatch。现在我已经实现了本地通知,但由于某些原因,通知显示在 iPhone 模拟器上,而不是 iWatch (WatchOS 2) 模拟器上。

我在 applicationDidFinishLaunchingWithOptions: 中添加了以下代码

UIMutableUserNotificationAction *action1;
action1 = [[UIMutableUserNotificationAction alloc] init];
[action1 setActivationMode:UIUserNotificationActivationModeBackground];
[action1 setTitle:@"Action 1"];
[action1 setIdentifier:kAction1];
[action1 setDestructive:NO];
[action1 setAuthenticationRequired:NO];

UIMutableUserNotificationAction *action2;
action2 = [[UIMutableUserNotificationAction alloc] init];
[action2 setActivationMode:UIUserNotificationActivationModeBackground];
[action2 setTitle:@"Action 2"];
[action2 setIdentifier:kAction2];
[action2 setDestructive:NO];
[action2 setAuthenticationRequired:NO];

UIMutableUserNotificationCategory *actionCategory;
actionCategory = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory setIdentifier:kAction3];
[actionCategory setActions:@[action1, action2]
forContext:UIUserNotificationActionContextDefault];

NSSet *categories = [NSSet setWithObject:actionCategory];
UIUserNotificationType types = (UIUserNotificationTypeAlert|
UIUserNotificationTypeSound|
UIUserNotificationTypeBadge);

UIUserNotificationSettings *settings;
settings = [UIUserNotificationSettings settingsForTypes:types
categories:categories];

[[UIApplication sharedApplication] registerUserNotificationSettings:settings];

您是否能够在模拟器中获取 WatchOS 本地通知的通知?

最佳答案

在模拟器上运行你的 watch 应用程序,从 iPhone 模拟器安排 通知 并锁定 iPhone 模拟器屏幕,保持 watch 模拟器处于事件状态,在这种情况下,当通知被触发时,它会传送到您的 watch 模拟器上。当您在实际设备上进行测试时,情况也是如此。

关于ios - 我可以在 WatchOS 2 模拟器上测试本地通知吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35278338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com