Zol*_*olt 1 notifications objective-c push-notification ios
我对objective-c完全不熟悉,并且将这个问题用了2个小时,这让我没有任何有用的信息.事实上,我比起初时更加困惑.我还为iOS 6更新了一本教科书,但这个问题完全没用.
我只是希望用户在我的应用程序中输入特定时间(可能来自日期选择器,我还没有决定),然后稍后收到通知(例如,在用户输入之前5小时).
下面的示例图片说明了我的意思.假设用户在上午2:09进入,然后在下午9:09(前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");
}
Run Code Online (Sandbox Code Playgroud)
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];
Run Code Online (Sandbox Code Playgroud)
这将为您的应用安排本地通知.如果您的应用程序处于后台,系统本身将发出警报消息.但是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.你必须回复通知.
| 归档时间: |
|
| 查看次数: |
1042 次 |
| 最近记录: |