gpt4 book ai didi

ios - 在完成启动后或在我们的应用程序内启用/禁用推送通知

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:23:00 25 4
gpt4 key购买 nike

完成启动后,我需要在我们的应用程序中启用/禁用或注册/取消注册推送通知。我将在启动后和我的应用程序“帐户设置”中执行此功能

我尝试了下面的代码,但它不起作用。

 if (cell.switchButton.on) {
if ([[UIApplication sharedApplication]respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
}
else {
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
}

我的要求:我将以编程方式在我的应用程序中启用或禁用通知切换,而不是直接转到设置 -> 通知。

最佳答案

你不应该使用unregisterForRemoteNotifications,它会像苹果所说的那样完全注销APNS

You should call this method in rare circumstances only, such as when a new version of the app removes support for all types of remote notifications. Users can temporarily prevent apps from receiving remote notifications through the Notifications section of the Settings app.

这里是 link

如果您在服务器端实现禁用推送通知会更好。只是告诉您的服务器人员提供不发送 APN 的服务。

或者您也可以打开设置应用程序的通知部分,如下所示

if (&UIApplicationOpenSettingsURLString != NULL){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}

关于ios - 在完成启动后或在我们的应用程序内启用/禁用推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39406398/

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