首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UILocalNotification不点火

UILocalNotification不点火
EN

Stack Overflow用户
提问于 2011-08-08 21:42:15
回答 3查看 4.8K关注 0票数 3

我对Cocoa和Objective非常陌生,但我已经得到了相当大的分数,我正在试验UIKit。我有一个操作链接到一个按钮,该按钮可以更改标签并触发一个UILocalNotification,这就是action方法:

代码语言:javascript
复制
- (IBAction)changeLabel:(id)sender {
    self.LabelOne.text = @"WHAT UPPP!";
    self.NotifyOne.alertBody = @"Testtttttt";
    self.NotifyOne.alertAction = @"Got It.";
    self.NotifyOne.fireDate = nil;
}

没有错误或警告,但它只是没有触发。我的动作方法有什么问题吗?

更新

下面是包含UILocalNotification的App初始化

代码语言:javascript
复制
@interface LearnAppDelegate : NSObject <UIApplicationDelegate> {
    UIButton *_ModifyLabelButton;
    UILabel *_LabelOne;
    UILocalNotification *_NotifyOne;
}

@property (nonatomic, retain) IBOutlet UILocalNotification *NotifyOne;
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-08-08 21:53:09

如果你想要的话,就在没有时间表的情况下表演。当您按下一个按钮),然后使用UIAlertView或添加[application presentLocalNotificationNow:self.NotifyOne];到您的代码。

更新

删除IBOutlet并使UILocalNotification的两个声明都具有相同的名称。例如:

代码语言:javascript
复制
@interface LearnAppDelegate : NSObject <UIApplicationDelegate> {
    UIButton *_ModifyLabelButton;
    UILabel *_LabelOne;
    UILocalNotification *NotifyOne;
}

@property (nonatomic, retain) UILocalNotification *NotifyOne;

请记住在您的实现( synthesize )文件中使用.m。

也可以尝试这样做:

代码语言:javascript
复制
- (IBAction)changeLabel:(id)sender {
    self.LabelOne.text = @"WHAT UPPP!";
    NotifyOne = [[UILocalNotification alloc] init];
    if (NotifyOne) {
        NotifyOne.alertBody = @"Testtttttt";
        NotifyOne.alertAction = NSLocalizedString(@"Got It.", nil);
        NotifyOne.fireDate = nil;
        NotifyOne.soundName = nil;
        NotifyOne.applicationIconBadgeNumber = 0;
        [application presentLocalNotificationNow:NotifyOne];
        [NotifyOne release];
        NotifyOne = nil;
    }
}
票数 6
EN

Stack Overflow用户

发布于 2011-08-08 21:48:12

你安排过警报吗?这是我用来报警的代码。

代码语言:javascript
复制
UILocalNotification *alarm = [[UILocalNotification alloc] init];
    if (alarm) {
        alarm.fireDate = [NSDate date];
        alarm.timeZone = [NSTimeZone defaultTimeZone];
        alarm.repeatInterval = 0;
        alarm.soundName = @"alarmsound.caf";
        alarm.alertBody = @"Test message...";       
        [[UIApplication sharedApplication] scheduleLocalNotification:alarm];
        [alarm release];
    }
票数 3
EN

Stack Overflow用户

发布于 2011-08-08 21:49:18

如果不为UILocalNotification提供fireDate并将其与应用程序实例一起调度,则不会触发它。如果您试图立即提出某种警告,也许您应该尝试使用UIAlertView

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

https://stackoverflow.com/questions/6988986

复制
相关文章

相似问题

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