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

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

问题描述

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

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

谢谢

推荐答案

是的,本地通知适用于模拟器.但是,如果您想在应用程序处于前台时看到通知,请确保您在应用程序委托中实现了 application: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 notification 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天全站免登陆