HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了检查用户是否允许本地通知. iOS 8. Obj-C大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如果用户允许本地通知,是否没有简单的测试方法?在我拒绝发送本地通知后,我在控制台中发现了警告.当相关事件发生时,它表示该应用程序尝试发送通知,即使用户不允许它.我想在尝试显示通知之前检查是否允许它.在我的情况下看评论,我该怎么做?

我的代码是:

app = [UIApplication sharedApplication];
-(void)showBACkgroundNotification:(NSString *) message {
//check if app is in BACkground and check if local notifications are allowed.
    if (app.applicationState == UIApplicationStateBACkground /*&& localnotificationsAreAllowed*/){
        UIlocalnotification *note = [[UIlocalnotification alloc]init];
        note.alertBody = message;
        note.fireDate = [NSDate dateWithTimeIntervalSinceNow:0.0];
        [app schedulelocalnotification :note];
    }
}

我得到用户提示,如下所示:

UIUserNotificationSetTings *setTings;
if ([app     respondsToSELEctor:@SELEctor(registerUserNotificationSetTings:)])
{
    setTings = [UIUserNotificationSetTings setTingsForTypes:(UIUserNotificationTypeBadge|UIUserNotificationTypeAlert|UIUserNotification    TypeSound) categories:nil];
    [app registerUserNotificationSetTings:setTings];
}

我不能使用设置对象?

编辑:我想我已经解决了.这似乎有效.

-(void)showBACkgroundNotification:(NSString *) message {
    if (app.applicationState == UIApplicationStateBACkground && [app currentUserNotificationSetTings].types != UIUserNotificationTypeNonE){
        UIlocalnotification *note = [[UIlocalnotification alloc]init];
        note.alertBody = message;
        note.fireDate = [NSDate dateWithTimeIntervalSinceNow:0.0];
        [app schedulelocalnotification :note];
    }
}

解决方法

这是我在不太具体的情况下使用的内容
+ (BOOL)notificationsEnabled {
    UIUserNotificationSetTings *setTings = [[UIApplication sharedApplication] currentUserNotificationSetTings];
    return setTings.types != UIUserNotificationTypeNone;
}

我通常在通知管理器中保留一组这些类型的方法.

大佬总结

以上是大佬教程为你收集整理的检查用户是否允许本地通知. iOS 8. Obj-C全部内容,希望文章能够帮你解决检查用户是否允许本地通知. iOS 8. Obj-C所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。