在模拟器中的iphone本地通知 [英] iphone local notification in simulator

查看:127
本文介绍了在模拟器中的iphone本地通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚下载了xcode并尝试制作本地通知示例。问题是本地通知是否在模拟器中有效?

I just downloaded xcode and trying to make local notification example. The question is if local notification works in simulator?

谢谢

推荐答案

是的,本地通知适用于模拟器。但是,如果您希望在应用程序位于前台时看到nofication,请确保在应用委托中实现应用程序:didreceiveLocalNotification:

Yes, local notifications work with the simulator. However, make sure you are implementing application:didreceiveLocalNotification in your app delegate if you want to see the nofication while your app is in the foreground:

- (void)application:(UIApplication *)application
    didReceiveLocalNotification:(UILocalNotification *)notification
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"MyAlertView"
        message:notification.alertBody
        delegate:self cancelButtonTitle:@"OK"
        otherButtonTitles:nil];
    [alertView show];
    if (alertView) {
        [alertView release];
    }
}

否则,请确保安排通知一段时间在将来,关闭应用程序,以便查看Apple示例工作:

Otherwise, make sure you schedule your notification for some time in the future, then close the application, in order to see the Apple sample work:

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil) return;
NSDate *fireTime = [[NSDate date] addTimeInterval:10]; // adds 10 secs
localNotif.fireDate = fireTime;
localNotif.alertBody = @"Alert!";
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];

很容易认为你没有正确实现测试代码,而你只是不处理应用程序运行时的事件。

It's easy to think you're not implementing the test code correctly, and you just aren't handling the event while the app is running.

这篇关于在模拟器中的iphone本地通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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