【问题标题】:iPhone sdk: how to increase the local notification countiPhone sdk:如何增加本地通知计数
【发布时间】:2011-03-12 05:45:05
【问题描述】:

您好,我正在使用 Google 日历,当活动开始时,我必须在本地通知中保留用户活动。

为此我必须显示通知,如果用户一次有两个事件,则本地通知计数必须在应用程序图标上增加。(如果我一次有两个事件,计数也只显示一个本地通知依靠应用程序图标)。

请建议我如何增加应用图标上的本地通知计数。

请检查我的代码。

//Local notifications delegates and methods.
Class cls = NSClassFromString(@"UILocalNotification");

if (cls != nil) {

UILocalNotification *notif = [[cls alloc] init];
notif.fireDate = [[when startTime] date];
notif.timeZone = [NSTimeZone defaultTimeZone];

// Notification details
notif.alertBody =  titles;// here title is the key word for the event

// Set the action button
notif.alertAction = nil;
notif.soundName = UILocalNotificationDefaultSoundName;
notif.applicationIconBadgeNumber = 1;


// Specify custom data for the notification
NSDictionary *userDict = [NSDictionary dictionaryWithObject:titles forKey:kRemindMeNotificationDataKey];

notif.userInfo = userDict;

// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
[notif release];

}

谢谢

【问题讨论】:

    标签: iphone objective-c uilocalnotification


    【解决方案1】:

    假设变量 count 包含要显示在图标徽章上的正确数字,您只需执行以下操作:

    [UIApplication sharedApplication].applicationIconBadgeNumber = count;
    

    【讨论】:

      【解决方案2】:

      我的答案需要一个数据库:

      创建一个按日期和计数排序的数组(数据库)。当通知触发时,调用它的计数并使用显示它

      [[UIApplication sharedApplication] setApplicationIconBadgeNumber: badgeSortCount]

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-10-14
        • 2011-08-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-24
        • 2011-03-23
        相关资源
        最近更新 更多