UILocalNotification不触发 [英] UILocalNotification not firing

查看:115
本文介绍了UILocalNotification不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常是新的Cocoa Touch和Objective-C,但我已经得到了相当大的点,我正在试验UIKit。我有一个动作链接到一个按钮,更改标签并触发UILocalNotification,这是动作方法:

   - )changeLabel:(id)sender {
self.LabelOne.text = @WHAT UPPP!
self.NotifyOne.alertBody = @Testtttttt;
self.NotifyOne.alertAction = @Got It。
self.NotifyOne.fireDate = nil;
}

没有错误或警告,但它只是没有触发。

UPDATE

这是App Delegate初始化,包含<$ p code> UILocalNotification :

  @interface LearnAppDelegate:NSObject< UIApplicationDelegate& {
UIButton * _ModifyLabelButton;
UILabel * _LabelOne;
UILocalNotification * _NotifyOne;
}

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


解决方案

如果你希望没有时间表。当你按下一个按钮),然后使用 UIAlertView 或添加 [application presentLocalNotificationNow:self.NotifyOne]; 代码。



UPDATE



删除IBOutlet并同时声明UILocalNotification名称。例如:

  @interface LearnAppDelegate:NSObject< UIApplicationDelegate> {
UIButton * _ModifyLabelButton;
UILabel * _LabelOne;
UILocalNotification * NotifyOne;
}

@property(nonatomic,retain)UILocalNotification * NotifyOne;

请记住在实施中 synthesize m)文件。



也可尝试:

   - 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;
}
}


I am very new to Cocoa Touch and Objective-C but I've gotten the pretty big points down and I am experimenting with the UIKit. I have a action linked to a button that changes a label and fires a UILocalNotification and this is the action method:

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

There are no errors or warnings, but it's just not firing. Is there anything wrong with my action method?

UPDATE
Here is the App Delegate initialization that contains the UILocalNotification:

@interface LearnAppDelegate : NSObject <UIApplicationDelegate> {
    UIButton *_ModifyLabelButton;
    UILabel *_LabelOne;
    UILocalNotification *_NotifyOne;
}

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

解决方案

If you are wanting it show without a schedule (eg. when you press a button) then either use UIAlertView or add [application presentLocalNotificationNow:self.NotifyOne]; to your code.

UPDATE

Remove IBOutlet and make both declarations of UILocalNotification the same name. For example:

@interface LearnAppDelegate : NSObject <UIApplicationDelegate> {
    UIButton *_ModifyLabelButton;
    UILabel *_LabelOne;
    UILocalNotification *NotifyOne;
}

@property (nonatomic, retain) UILocalNotification *NotifyOne;

Remember to synthesize in your implementation (.m) file.

Also try this instead:

- (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;
    }
}

这篇关于UILocalNotification不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆