繁体   English   中英

等待一段时间后向用户发送通知

[英]Send notification to user after waiting a certain amount of time

我是对Objective-c完全陌生的人,在这个问题上搜索了2个小时后,我没有得到任何有用的信息。 实际上,我比开始时更加困惑。 我还为iOS 6更新了一本教科书,但是对于此问题完全没有用。

我只是希望用户在我的应用程序中输入某个时间(也许是从日期选择器中输入,我尚未决定),然后稍后再收到通知(例如,用户输入时间之前的5小时)。

下面的示例图片说明了我的意思。 假设用户输入了凌晨2:09,然后在9:09 pm(5小时之前)进入了图示通知。

我已经从这个来源找到了这段代码,但是我什至不确定这是否是我需要的:

// Add an observer that will respond to loginComplete
[[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(showMainMenu:) 
                                                 name:@"loginComplete" object:nil];


// Post a notification to loginComplete
[[NSNotificationCenter defaultCenter] postNotificationName:@"loginComplete" object:nil];


// the function specified in the same class where we defined the addObserver
- (void)showMainMenu:(NSNotification *)note {
    NSLog(@"Received Notification - Someone seems to have logged in"); 
}

该代码似乎更多用于NSNotificationCenter。 它所做的只是在按钮按下事件之后将消息打印到控制台。

有人可以修改给定的代码,还是提供示例以说明如何获得所需的结果。

您不必为我编写我的应用。 那不是我要的。 只需编写示例代码或链接。

重申一下,我希望用户在控件中输入一个时间,该应用将确定在该时间之前几个小时的时间,并在那时发出通知。 我可以弄清楚控件和时间的东西,但是通知的东西确实让我很困惑。 这就是我需要帮助的地方。

如果有人幸运地找到了关于此的很好的教程,那也肯定会对我有帮助。

鉴于很难在Google上找到有关此问题的帮助,并且这对于许多人来说可能是一个常见问题,因此任何数量的帮助都可能不仅使我自己受益,还会使其他看到此问题的人受益。

提前致谢。

通知

您必须为此使用UILocalNotification 这是教程

     UILocalNotification *notification = [[UILocalNotification alloc]init];
    notification.fireDate = self.datePicker.date;
    notification.alertBody = "Wake up!!";
    notification.soundName = UILocalNotificationDefaultSoundName;     
    notification.alertAction= @"view details";

    [[UIApplication sharedApplication]scheduleLocalNotification:notification];
    [notification release];

这将为您的应用安排本地通知。 如果您的应用程序处于后台,则系统本身将发出警报消息。 但是, If the application is foremost and visible when the system delivers the notification, no alert is shown, no icon is badged, and no sound is played. However, the application:didReceiveLocalNotification: is called if the application delegate implements it. If the application is foremost and visible when the system delivers the notification, no alert is shown, no icon is badged, and no sound is played. However, the application:didReceiveLocalNotification: is called if the application delegate implements it. 在那里您必须响应通知。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM