如何在iOS中查看用户是否见过推送通知权限提醒视图?

时间:2021-01-02 16:47:36

I wanted to show a message to users at the start of the app just before showing the push notification permissions alert view. In order to determine whether I should display the message, I need to know whether user has seen the push notification permissions alert view before.

我想在显示推送通知权限警告视图之前向用户显示一条消息。为了确定是否应该显示消息,我需要知道用户以前是否看过push notification permissions alert视图。

1 个解决方案

#1


3  

You can use NSUserDefaults.

您可以使用NSUserDefaults。

After you call regusterNotifications: which shows the permissions.

调用regusterNotifications之后:它显示权限。

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"hasShown"];
[[NSUserDefaults standardUserDefaults] synchronize];

To check if it has shown, assuming that means the Boolean value for hasShown is Yes.

要检查它是否显示,假设这意味着hasshow的布尔值是Yes。

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"hasShown"])
    // user has seen before

Note that this only checks if the permissions request has been sent before. This does not validate whether your push notifications is still activated for the given app.

注意,这只检查权限请求是否已发送。这并不能验证您的推送通知是否仍然为给定的应用程序激活。

#1


3  

You can use NSUserDefaults.

您可以使用NSUserDefaults。

After you call regusterNotifications: which shows the permissions.

调用regusterNotifications之后:它显示权限。

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"hasShown"];
[[NSUserDefaults standardUserDefaults] synchronize];

To check if it has shown, assuming that means the Boolean value for hasShown is Yes.

要检查它是否显示,假设这意味着hasshow的布尔值是Yes。

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"hasShown"])
    // user has seen before

Note that this only checks if the permissions request has been sent before. This does not validate whether your push notifications is still activated for the given app.

注意,这只检查权限请求是否已发送。这并不能验证您的推送通知是否仍然为给定的应用程序激活。