小编Gid*_*eon的帖子

重复本周特定日期的本地通知(Swift 3 IOS 10)

我正在尝试安排一周中特定日期的本地通知(例如周一,周三等),然后每周重复一次.这是用于设置通知的屏幕的外观:

在此输入图像描述

用户可以选择通知时间和重复日期.

我调度单个非重复通知的方法如下所示:

static func scheduleNotification(reminder: Reminder) {
    // Setup notification content.
    let content = UNMutableNotificationContent()

    //content.title = NSString.localizedUserNotificationString(forKey: "Reminder", arguments: nil)
    content.body = NSString.localizedUserNotificationString(forKey: reminder.reminderMessage, arguments: nil)
    content.sound = UNNotificationSound.default()


    // Configure the triger for specified time.
    // 
    let dateComponentes = reminder.dateComponents
    // TODO: Configure repeating alarm

    // For the testing purposes we will not repeat the reminder
    let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponentes, repeats: false)

    // Create the request object.
    let request = UNNotificationRequest(identifier: "\(reminder.reminderId)", content: content, trigger: trigger) …
Run Code Online (Sandbox Code Playgroud)

notifications ios swift swift3

8
推荐指数
2
解决办法
6635
查看次数

后台活动识别

我正在制作一个使用 ActivityRecognition API 在后台跟踪用户活动的应用程序,如果用户在指定的时间段(例如 1 小时)内保持在同一个地方,那么系统会推送通知告诉用户散步。我已经实现了活动识别,但仅适用于打开应用程序的情况。显然,Google API 客户端需要保持连接才能发送活动更新。我的问题是 - 对于后台活动跟踪,什么是更好的解决方案:

1)在主activity(或单独activity)中实现AlarmManager,每30秒唤醒一次activity,连接Google API Client到Play Services,然后发送PendingIntent给IntentService进行activity分析

2)创建一个单独的服务(不是 IntentService)在后台持续运行(单独的线程),这将保持 API 客户端连接,并将活动更新发送到 IntentService。因此,系统将有 2 个服务:1) 保持 API 客户端连接到 Play 服务并将定期活动更新发送到 IntentService 进行分析的服务;2) IntentService 用于接收来自 Service 的活动更新,并分析数据。

3)其他一些解决方案(由你们提供)

评论:我的导师建议我使用AlarmManager,但您通常将其用于网络更新之类的事情,因此间隔通常超过10分钟,而我需要30秒-1分钟。所以我很犹豫要不要使用它。

我之前也在这里看到过很多类似的问题,但我还没有找到任何明确的答案。

service android activity-recognition

3
推荐指数
1
解决办法
3685
查看次数

从UIDatePicker中提取小时和分钟

我在时间模式下设置了UIDatePicker,并且具有引用该日期选择器的属性.在Swift 3中设置为时间模式时,我不知道如何从UIDatePicker中提取小时和分钟组件.请帮忙

uidatepicker ios swift3

3
推荐指数
1
解决办法
4343
查看次数