当服务器发送静默通知时,我想检查用户是否处于正确状态,然后如果用户处于正确状态则发出本地通知,如果用户不在正确状态则不执行任何操作正确的状态。
这可行吗?
谢谢!
答案 0 :(得分:0)
如果您使用df_a['time'] = pd.to_datetime(df_a['time'], format='%d.%m.%Y %H:%M:%S')
df_b['start-date'] = pd.to_datetime(df_b['start-date'], format='%d.%m.%Y %H:%M:%S')
df_b['end-date'] = pd.to_datetime(df_b['end-date'], format='%d.%m.%Y %H:%M:%S')
def check_min_timedelta(x):
"""
Create a timedelta between time and end-date
Return maturity for the row with the minimum time date
"""
end_diff = abs(df_b['end-date'][df_b['project'] == x[1]] - x[0]).idxmin()
return df_b['maturity'].loc[end_diff]
# update def date_query
def date_query(x):
mask = df_b[['project', 'maturity']][df_b[['start-date', 'end-date']].apply(lambda y: ((x[0] >= y[0]) & (x[0] <= y[1])), axis=1)].reset_index(drop=True)
result = mask['maturity'][mask['project'] == x[1]].reset_index(drop=True)
if result.empty:
result = check_min_timedelta(x)
return result
# call function
df_a['maturity'] = df_a.apply(lambda x: date_query(x), axis=1)
发送推送通知,它将是无提示推送(请参阅Apple的local and remote notification guide)。
然后,您想使用"content-available": 1
有条件地安排本地通知,并为UNUserNotificationCenter.current().add()
实现委托方法。
答案 1 :(得分:0)
这不是一个好主意。 系统将后台通知视为低优先级。 证明:https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app
因此,后台通知不适合您。 在某些情况下,如果您不想显示通知,则只需 UNUserNotificationCenterDelegate 的实现方法不要调用完成处理程序:
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
guard self.shouldShowNotification(notification) else { return } // don't call completion handler if we're don't want to show push
completionHandler(.alert)
}
func shouldShowNotification(_ notification: UNNotification) -> Bool {
if ... {
return true
} else {
return false
}
}