【问题标题】:How to show an alertview on receiving push notifications when app is not launched?未启动应用程序时如何在接收推送通知时显示警报视图?
【发布时间】:2013-11-03 01:32:33
【问题描述】:

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

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

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 是否支持任何方式在应用未启动的情况下接收推送通知时执行代码?

有什么想法吗?

【问题讨论】:

    标签: ios push-notification


    【解决方案1】:

    使用 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;
    }
    

    欲了解更多信息over_Here

    【讨论】:

    • 请注意 application:didReceiveRemoteNotification: 在您的应用程序处于前台时或用户选择与通知交互时调用推送通知。
    • 感谢库马尔的回答!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-15
    • 1970-01-01
    • 2013-03-12
    相关资源
    最近更新 更多