【问题标题】:Can i detect if the user disables push notification globally on trigger.io?我可以检测用户是否在 trigger.io 上全局禁用推送通知吗?
【发布时间】:2015-01-30 12:44:24
【问题描述】:

我正在使用 trigger.io 制作支持推送通知的应用程序。这工作正常。如果我全局禁用推送通知,应用程序将停止接收任何推送通知。 trigger.io 中是否有任何命令可以确定用户是否通过设置启用或禁用了我的应用程序的推送通知。

【问题讨论】:

    标签: android ios push-notification trigger.io pushwoosh


    【解决方案1】:

    你可以使用

    forge.parse.push.subscribedChannels(成功,错误

    这将返回他们订阅的频道列表,如果您的频道不存在,则他们没有订阅,并且在回调中执行您想要的操作(订阅等)

    【讨论】:

    • 但是 parse 如何知道用户是否禁用了推送通知(通过设置页面)。
    • 我认为全局关闭推送通知不会触发 parse-unsubscribe 方法。
    【解决方案2】:

    您实际上可以从 iOS 获取推送设置,但是您需要将其实现为您自己的 native module。我在基于 Trigger.io 的应用程序中使用它:

    + (void)getPushStatus:(ForgeTask*)task {
    
        NSArray *pushStatus;
    
        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8) {
            UIUserNotificationSettings *settings = [[UIApplication sharedApplication] currentUserNotificationSettings];
            UIUserNotificationType notificationTypes = settings.types;
    
            if (notificationTypes == UIUserNotificationTypeBadge) {
                pushStatus = [NSArray arrayWithObjects: @"badge", nil];
            } else if (notificationTypes == UIUserNotificationTypeAlert) {
                pushStatus = [NSArray arrayWithObjects: @"alert", nil];
            } else if (notificationTypes == UIUserNotificationTypeSound) {
                pushStatus = [NSArray arrayWithObjects: @"sound", nil];
            } else if (notificationTypes == (UIUserNotificationTypeBadge | UIUserNotificationTypeAlert)) {
                pushStatus = [NSArray arrayWithObjects: @"badge", @"alert", nil];
            } else if (notificationTypes == (UIUserNotificationTypeBadge | UIUserNotificationTypeSound)) {
                pushStatus = [NSArray arrayWithObjects: @"badge", @"sound", nil];
            } else if (notificationTypes == (UIUserNotificationTypeAlert | UIUserNotificationTypeSound)) {
                pushStatus = [NSArray arrayWithObjects: @"alert", @"sound", nil];
            } else if (notificationTypes == (UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound)) {
                pushStatus = [NSArray arrayWithObjects: @"badge", @"alert", @"sound", nil];
            } else {
                // notificationTypes == UIUserNotificationTypeNone
                pushStatus = [[NSArray alloc] init];
            }
        } else {
            UIRemoteNotificationType notificationTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
    
            if (notificationTypes == UIRemoteNotificationTypeBadge) {
                pushStatus = [NSArray arrayWithObjects: @"badge", nil];
            } else if (notificationTypes == UIRemoteNotificationTypeAlert) {
                pushStatus = [NSArray arrayWithObjects: @"alert", nil];
            } else if (notificationTypes == UIRemoteNotificationTypeSound) {
                pushStatus = [NSArray arrayWithObjects: @"sound", nil];
            } else if (notificationTypes == (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)) {
                pushStatus = [NSArray arrayWithObjects: @"badge", @"alert", nil];
            } else if (notificationTypes == (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)) {
                pushStatus = [NSArray arrayWithObjects: @"badge", @"sound", nil];
            } else if (notificationTypes == (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)) {
                pushStatus = [NSArray arrayWithObjects: @"alert", @"sound", nil];
            } else if (notificationTypes == (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)) {
                pushStatus = [NSArray arrayWithObjects: @"badge", @"alert", @"sound", nil];
            } else {
                // notificationTypes == UIRemoteNotificationTypeNone
                pushStatus = [[NSArray alloc] init];
            }
        }
    
        [task success:pushStatus];
    }
    

    不要被那一堆代码吓到。前半部分适用于 >=iOS8,后半部分适用于以下所有内容。它基本上告诉您用户为您的应用激活了哪种类型的通知。

    返回值将是一个由“badge”、“alert”和/或“sound”组成的数组。

    如果用户为您的应用禁用推送,则数组将为空。


    PS:我不擅长 Objective-C,因为上面的代码显然可以做得更好。但是,它仍然对我有用;)


    编辑:我刚刚意识到您还询问了有关 Android 的问题。我的回答只与 iOS 有关。根据这篇帖子Android 4.1: How to check notifications are disabled for the application?,无法在 Android 上获取该信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多