在通知设置(设置 - >通知 - > AnyAppName)中,有5个项目,每个项目都有一个切换按钮,Sounds
,Badge App Icon
,Show on Lock Screen
,{{1 },Show in History
。
我正在使用Show as Banners
来获取用户的设置并宣传相应的提醒。
它可能返回值[[[UIApplication sharedApplication] currentUserNotificationSettings] types]
表示0~7
,Sound
和Badge
的任意组合。问题是,我们是否能够检测到Banners
,Show on Lock Screen
?
此外,在设置页面的底部,theres是一个名为Show in History
的{{1}}选项,它有三个选项:OPTIONS
,Show Previews
和{{1} }。我们能够以编程方式为此设置用户吗?
答案 0 :(得分:0)
您应该使用从iOS 10开始支持的UserNotifications框架。
这样您就可以通过getNotificationSettingsWithCompletionHandler:
UNUserNotificationCenter
函数检索UNNotificationSettings
。
在Show in History
中,您可以检查一些值:
Show on Lock Screen
)Show as Banners
)[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
if(settings.authorizationStatus == UNAuthorizationStatusAuthorized) {
//notifications are enabled for this app
if(settings.notificationCenterSetting == UNNotificationSettingEnabled ||
settings.lockScreenSetting == UNNotificationSettingEnabled ||
(settings.alertSetting == UNNotificationSettingEnabled && settings.alertStyle != UNAlertStyleNone)) {
//the user will be able to see the notifications (on the lock screen, in history and/or via banners)
dispatch_async(dispatch_get_main_queue(), ^(){
//now for instance, register for remote notifications
//execute this from the main queue
[[UIApplication sharedApplication] registerForRemoteNotifications];
});
}
else {
//the user must change notification settings in order te receive notifications
}
}
else {
//request authorization
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) {
if(granted) {
dispatch_async(dispatch_get_main_queue(), ^(){
//now for instance, register for remote notifications
//execute this from the main queue
[[UIApplication sharedApplication] registerForRemoteNotifications];
});
}
else {
//user denied the authorization request
//the user must change notification settings in order te receive notifications
}
}
}
}];
)例如:
import tensorflow as tf
input_tensor = tf.placeholder(dtype=tf.float32, shape=[None, 16, 16, 3])
print(input_tensor.shape)
conv_filter = tf.get_variable('conv_filter', shape=[2, 2, 3, 6], dtype=tf.float32)
conv1 = tf.nn.conv2d(input_tensor, conv_filter, strides=[1, 2, 2, 1], padding='SAME')
print(conv1.shape)
deconv_filter = tf.get_variable('deconv_filter', shape=[2, 2, 6, 3], dtype=tf.float32)
deconv = tf.nn.conv2d_transpose(input_tensor, filter=deconv_filter,
output_shape=tf.shape(input_tensor),
strides=[1, 2, 2, 1],
padding='SAME')
print(deconv.shape)
t = tf.reduce_mean(deconv)
g = tf.train.AdamOptimizer(0.01).minimize(t)