-1

我正在开发假来电的应用程序。

为此,我现在正在使用本地通知。

我按照设定的时间收到通知,但它给了我弹出窗口,就像默认通知一样。

相反,我必须从 XIB 或通过编码显示视图。

那么,有没有办法用localnotification设置自定义视图呢?

或者我可以使用 NSThread 来获得上述输出吗?

如果有任何其他方法可以获得disered输出,请告诉我。

提前致谢


这就是我正在做的设置通知。

-(void)addNotification
{

        UILocalNotification *localNotification = [[UILocalNotification alloc] init];
        [localNotification setFireDate:[NSDate dateWithTimeIntervalSinceNow:5]];
        [localNotification setAlertAction:@"Answer"];

        [localNotification setAlertBody:[NSString stringWithFormat:@"%@\n\n %@",[txt_CallerName text],[txt_CallerNumber text]]];
        [localNotification setHasAction: YES];
        [localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]];

        [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; //Schedule the notification with the system

    [alertNotification setHidden:NO];
}
4

2 回答 2

0

UILocalNotification目前无法在接收 a 时显示自定义界面。UILocalNotification如果您的应用程序在前台时碰巧收到了,则有可能。但如果它在前台,则无论如何您都可以显示您的自定义界面。

您捕获本地通知触发并在发生这种情况时执行某些操作的方式是-application:didReceiveLocalNotification:UIApplicationDelegate. 可以说,这是您问题的答案,但它无法实现您明确寻找的目标,即通过显示自定义 UI 在特定时间点启动您的应用程序,因为它只会在应用程序运行时发生已经在前台。

于 2012-06-07T11:43:42.883 回答
-1

您可以使用 NSNotificationCenter 来引发通知和事件发生,只需调用通知方法并显示您的自定义视图。

1.注册通知如下:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(displayCustomView) name:@"EventNotification" object:nil];

2.当事件发生时,通知方法如下:

[[NSNotificationCenter defaultCenter] postNotificationName:@"EventNotification" object:nil];

3.在通知方法中显示您的自定义视图,如下所示:

-(void)displayCustomView
{
   //initialize custom view and display as required.
}
于 2012-06-07T11:36:13.683 回答