簡體   English   中英

UILocalNotification沒有開火

[英]UILocalNotification not firing

新的可可觸摸和Objective-C,但我得到了下來漂亮的大點,我與UIKit的試驗。 我有一個鏈接到一個按鈕的動作,該按鈕可以更改標簽並觸發UILocalNotification,這是動作方法:

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

沒有錯誤或警告,但它只是沒有觸發。 我的行動方法有什么問題嗎?

UPDATE
以下是包含UILocalNotification的App Delegate初始化:

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

你有沒有安排鬧鍾? 這是我用來觸發警報的代碼。

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

一個UILocalNotification不會解雇,如果你不使用它提供fireDate與您的應用實例調度。 如果您嘗試立即提供某種警報,也許您應該嘗試使用UIAlertView

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM