【问题标题】:how to notify user in ios, while app is closed/ inbackground如何在 ios 中通知用户,而应用程序已关闭/在后台
【发布时间】:2012-04-24 09:11:12
【问题描述】:

我想在到达“时间”时通知用户。

例如:

我有一个包含许多行的 tableview。这些行类似于提醒,用户可以在其中设置提醒的日期和时间。
因此,提醒连续设置为 4 月 24 日 12:15。
此时App已关闭。

那么我怎样才能通知用户这个时间已经到了呢?

有没有办法做到这一点没有苹果推送通知服务?

编辑 1:
感谢您的回答,以下是本地通知的示例:

//This example adds 20 seconds to current time, use it for testing 
    UILocalNotification *localNotification = [[UILocalNotification alloc] init];



    NSDate *currentDate = [NSDate date];
    NSDate *currentDatePlus = [currentDate dateByAddingTimeInterval:20];

    localNotification.fireDate = currentDatePlus;
    localNotification.alertBody = @"Hallo ayFon User";
    localNotification.soundName = UILocalNotificationDefaultSoundName;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
    [localNotification release];

编辑 2:

//Add this for iOS 5 Notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: 
 UIRemoteNotificationTypeAlert |
 UIRemoteNotificationTypeSound];

【问题讨论】:

    标签: iphone ios notifications push-notification reminders


    【解决方案1】:

    您必须使用 iOS 的本地通知。它们正是为了这个目的而完成的。

    您可以在此处找到文档:Local and Push Notification Programming Guide

    【讨论】:

      【解决方案2】:

      您不必使用推送通知 - 您可以改用本地通知。它们类似于推送通知,只是它们是在设备上生成的,因此您不需要网络连接。

      这是警报类应用相当常见的模式。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-23
        • 1970-01-01
        • 2016-04-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多