我正在使用trigger.io制作支持推送通知的应用。这很好用。如果我全局禁用推送通知,应用程序将停止接收任何推送通知。 trigger.io中是否有任何命令可以确定用户是否通过设置启用或禁用了我的应用程序的推送通知。
答案 0 :(得分:1)
您可以使用
forge.parse.push.subscribedChannels(成功,错误
这将返回他们订阅的频道列表,如果您的频道不在那里,那么他们没有订阅,并且在回调中做你想要的(订阅等)
答案 1 :(得分:0)
您实际上可以从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,下半部分用于以下所有内容。它基本上告诉您用户为您的应用激活了哪种类型的通知。
返回值将是一个由"徽章"," alert"组成的数组。和/或"声音"。
如果用户禁用了针对您的应用的推送,则该阵列将为空。
PS:我不擅长Objective-C,因为上面的代码显然可以做得更好。但是,它仍适用于我;)
编辑:我刚刚意识到你也问过Android。我的回答只与iOS有关。根据这篇文章Android 4.1: How to check notifications are disabled for the application?,它无法在Android上获取该信息。