1

我是 iOS 开发的新手。我想在应用程序处于非活动状态时显示接收推送通知的警报视图。

苹果表示,推送通知可以以警报消息的形式呈现,或者他们可以标记应用程序图标。

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction.html

我正在使用PushSharp发送推送通知。但通知仅在通知中心可见。我应该怎么做才能在 alertview 上显示它?

我知道我们可以编写代码来显示警报视图,例如

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

 UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"test title" message:@"test message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
        [alert show];

}

但是这个代码是在我点击通知和应用程序启动后执行的。我想在alertview设备收到推送通知后立即显示。

还有一个问题,Apple 是否支持任何方式在未启动应用程序时在接收推送通知时执行代码?

有任何想法吗?

4

1 回答 1

0

UIAlertView 不可能。你可以通过UILocalNotification来完成你的任务。

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{
    notifaication = [[UILocalNotification alloc] init];
    notifaication.timeZone = [NSTimeZone systemTimeZone];

    notifaication.alertBody = // Set the Body
    notifaication.alertAction =// @"Show me";
    backupAlarm.soundName = UILocalNotificationDefaultSoundName;
}

欲了解更多信息_这里

于 2013-10-24T11:20:06.317 回答