首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UILocalNotification nil userInfo

UILocalNotification nil userInfo
EN

Stack Overflow用户
提问于 2011-09-28 06:21:56
回答 1查看 408关注 0票数 2

我尝试取消本地通知。我附加了一个带有Id的dict,以便稍后查找:

代码语言:javascript
复制
+ (void) send:(NSString*)title actionText:(NSString *)actionText when:(NSDate *)when count:(NSInteger)count option:(NSDictionary *)options 
{
    UILocalNotification *notif = [[UILocalNotification alloc] init];
    //Setup code here...
    notif.userInfo = options;
    ALog(@"Sending notification %@ %@", notif.alertBody, notif.userInfo);
    //Print: Sending notification Task Col 0 0 {id = "1-1"};

    [[UIApplication sharedApplication] scheduleLocalNotification:notif];
}

然后当我试图找到它的时候:

代码语言:javascript
复制
+ (void) cancelNotification:(NSString *)theId {
    for(UILocalNotification *aNotif in [[UIApplication sharedApplication] scheduledLocalNotifications]) 
    {
        if([[aNotif.userInfo objectForKey:@"id"] isEqualToString:theId])
        {
            // Never come here: userInfo is nil!!!
        }
    }
}

userInfo始终为零。我发一条判决书:

代码语言:javascript
复制
NSMutableDictionary *info = [[NSMutableDictionary alloc] init];
        [info setObject:theId forKey:@"id"];

代码语言:javascript
复制
[NSMutableDictionary dictionaryWithObject:theId forKey:@"id"]

结果是一样的。(theId是NSString)

EN

回答 1

Stack Overflow用户

发布于 2012-12-06 21:37:49

本地通知仅有效,它具有有效的时间戳。因此,当您创建时,请确保它具有有效的时间戳。因此,它将出现在UIApplicaiton的scheduledNotifications中。

请让我知道你的意见。

例如: localNotification.fireDate = NSDate日期;

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7576375

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档