Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 使UILocalNotifications仅显示徽章_Iphone_Objective C_Xcode - Fatal编程技术网

Iphone 使UILocalNotifications仅显示徽章

Iphone 使UILocalNotifications仅显示徽章,iphone,objective-c,xcode,Iphone,Objective C,Xcode,我一直在研究UILocalNotification的API。我只想在firedate被击中时设置徽章编号。没有弹出窗口。我试着将我的通知设置为只有一个1号的徽章,而没有警报机构。但这不起作用 //Add new local push notification locationNotification.fireDate = date; locationNotification.timeZone = [NSTimeZone defaultTimeZone]; //locationNotificati

我一直在研究UILocalNotification的API。我只想在firedate被击中时设置徽章编号。没有弹出窗口。我试着将我的通知设置为只有一个1号的徽章,而没有警报机构。但这不起作用

//Add new local push notification
locationNotification.fireDate = date;
locationNotification.timeZone = [NSTimeZone defaultTimeZone];
//locationNotification.alertBody = [NSString stringWithFormat:body];
//locationNotification.alertAction = @"Ok";
//locationNotification.soundName = UILocalNotificationDefaultSoundName;
locationNotification.applicationIconBadgeNumber = 1;

这可能吗?我只想在他们打开应用程序后显示消息。

我在一个项目中完成了类似的工作。我只需要显示一个徽章号码,没有警告。您可能需要在通知中添加“声音”,我所做的是添加一个
0.5
second silent sound文件。我的代码看起来像这样

        UILocalNotification *notif = [[UILocalNotification alloc] init];
        notif.fireDate = [NSDate  date];
        notif.timeZone = [NSTimeZone defaultTimeZone];
        notif.soundName = @"silence.caf";
        notif.applicationIconBadgeNumber = 2;
        [[UIApplication sharedApplication] scheduleLocalNotification:notif];
        [notif release];

希望这有帮助

我在一个项目中完成了类似的工作。我只需要显示一个徽章号码,没有警告。您可能需要在通知中添加“声音”,我所做的是添加一个
0.5
second silent sound文件。我的代码看起来像这样

        UILocalNotification *notif = [[UILocalNotification alloc] init];
        notif.fireDate = [NSDate  date];
        notif.timeZone = [NSTimeZone defaultTimeZone];
        notif.soundName = @"silence.caf";
        notif.applicationIconBadgeNumber = 2;
        [[UIApplication sharedApplication] scheduleLocalNotification:notif];
        [notif release];

希望这有帮助

这是一个老问题,但希望这能帮助别人。我认为根本不可能安排无声的本地通知,但似乎是这样

这项工作:

    UILocalNotification* notification = [[UILocalNotification alloc] init];
    notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
    notification.timeZone = [NSTimeZone systemTimeZone];
    notification.alertBody = nil;        
    notification.applicationIconBadgeNumber = 99;
    [[UIApplication sharedApplication] scheduleLocalNotification:notification];
我还尝试向userInfo属性添加一些信息,以便在计划通知中识别此通知,但是这似乎阻止了通知被触发

相反,我现在使用静默音频文件作为soundName属性,以便对此进行测试。然而,无声音频文件似乎并不是真正获得火灾通知所必需的


如果您想做比将徽章更新为您在计划时知道的值更有用的事情,那么您需要使用静默推送通知并设置“内容可用”标志。

这是一个老问题,但希望这会对某人有所帮助。我认为根本不可能安排无声的本地通知,但似乎是这样

这项工作:

    UILocalNotification* notification = [[UILocalNotification alloc] init];
    notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
    notification.timeZone = [NSTimeZone systemTimeZone];
    notification.alertBody = nil;        
    notification.applicationIconBadgeNumber = 99;
    [[UIApplication sharedApplication] scheduleLocalNotification:notification];
我还尝试向userInfo属性添加一些信息,以便在计划通知中识别此通知,但是这似乎阻止了通知被触发

相反,我现在使用静默音频文件作为soundName属性,以便对此进行测试。然而,无声音频文件似乎并不是真正获得火灾通知所必需的


如果您想做比将徽章更新为您在计划时知道的值更有用的事情,那么您需要使用静默推送通知并设置“内容可用”标志。

感谢回复skram,我的代码中似乎唯一缺少的是声音名称。我尝试将其保留为UILocalNotificationDefaultSoundName,但这似乎没有什么不同。另外,请仔细检查您的
fireDate
预期时间是否有效。否则,您可能会期待一些没有真正发生的事情。如果我取消对alertbody的注释,则操作if正常。所以我认为火柴日期是可以的。我一直在读我可以把徽章设置为火柴日期的午夜。就您所知,localNotification是否只在该日期起作用?我现在正在和时间做比较,这可能是你的问题。将fireDate设置为比当前时间提前5分钟。背景或关闭应用程序,然后等待它启动,看看它是否会更改您的徽章。感谢您的回复skram,看起来我的代码中唯一缺少的是音名。我尝试将其保留为UILocalNotificationDefaultSoundName,但这似乎没有什么不同。另外,请仔细检查您的
fireDate
预期时间是否有效。否则,您可能会期待一些没有真正发生的事情。如果我取消对alertbody的注释,则操作if正常。所以我认为火柴日期是可以的。我一直在读我可以把徽章设置为火柴日期的午夜。就您所知,localNotification是否只在该日期起作用?我现在正在和时间做比较,这可能是你的问题。将fireDate设置为比当前时间提前5分钟。背景或关闭应用程序,然后等待它启动,看看它是否会更改您的徽章。