当用户第一次单击不允许权限时,如何设置第二次提示?

Posted

技术标签:

【中文标题】当用户第一次单击不允许权限时,如何设置第二次提示?【英文标题】:How to set a prompt for second time when user has clicked Don't allow for permissions the first time? 【发布时间】:2015-02-17 03:04:30 【问题描述】:

我想在用户第二次访问日历时添加提示,当最初用户单击“不允许”以获得日历的第一次访问权限时。

// For ios 6.0 and later
EKEventStore *_eventStore [[EKEventStore alloc] init];
[_eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) 
    // handle access here
];

EKEventStore *_reminderStore [[EKEventStore alloc] init];
[_reminderStore requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error) 
    // handle access here
];

这段代码是第一次询问用户权限,谁能告诉我,当用户点击不允许之后该怎么办?

【问题讨论】:

【参考方案1】:

您可以将第二个请求放在第一个请求的块中。

所以它看起来像这样:

// For iOS 6.0 and later
EKEventStore *_eventStore [[EKEventStore alloc] init];
[_eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) 
    if (granted) 
        [_eventStore requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error) 
            // handle access here
        ];
    
];

另外请记住,初始化 EKEventStore 的成本很高。尝试只使用它的一个实例。可以在documentation

中找到该信息和更多信息

【讨论】:

以上是关于当用户第一次单击不允许权限时,如何设置第二次提示?的主要内容,如果未能解决你的问题,请参考以下文章

用户先前不允许后如何再次请求麦克风访问权限?

如何在 Flutter 中请求和检查权限

如何在用户单击时滑动容器

单击第二次链接PrimeFaces时,构造函数不会调用

无法制作双向按钮(第一次单击使问题在第二次启用时禁用)

如何开启远程访问权限