嗨在我的應用程序我有通知部分,用戶可以啓用通知使用switch.After第一次啓動時,當用戶在交換機上我越來越不允許或從ios的alertview。如果用戶選擇不允許,切換將關閉,用戶將不會收到通知。現在,如果用戶嘗試在交換機上顯示提醒,請向用戶發送文字「請啓用設置通知」。任何人都可以提出建議。警報用戶啓用通知從ios設置
0
A
回答
0
您可以使用isRegisteredForRemoteNotifications方法檢查權限。
- (void)checkForNotificationPermission
{
if (!([[UIApplication sharedApplication] isRegisteredForRemoteNotifications] && [self pushNotificationsEnabled]))
{
// Show alert here
}
}
// For fixing iOS 8 issue mentioned here http://stackoverflow.com/a/28441181/1104384
- (BOOL)pushNotificationsEnabled
{
if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)])
{
UIUserNotificationType types = [[[UIApplication sharedApplication] currentUserNotificationSettings] types];
return (types & UIUserNotificationTypeAlert);
}
else
{
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
return (types & UIRemoteNotificationTypeAlert);
}
}
0
對於UILocalNotification
權限檢查以下,types
參數值將是無櫃面用戶已經不允許它。
[[UIApplication sharedApplication] currentUserNotificationSettings]
0
NSString *iOSversion = [[UIDevice currentDevice] systemVersion];
NSString *prefix = [[iOSversion componentsSeparatedByString:@"."] firstObject];
float versionVal = [prefix floatValue];
if (versionVal >= 8)
{
if ([[UIApplication sharedApplication] currentUserNotificationSettings].types != UIUserNotificationTypeNone)
{
NSLog(@" Push Notification ON");
}
else
{
NSString *msg = @"Please press ON to enable Push Notification";
UIAlertView *alert_push = [[UIAlertView alloc] initWithTitle:@"Push Notification Service Disable" message:msg delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Setting", nil];
alert_push.tag = 2;
[alert_push show];
NSLog(@" Push Notification OFF");
}
}
else
{
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types != UIRemoteNotificationTypeNone)
{
NSLog(@" Push Notification ON");
}
else
{
NSString *msg = @"Please press ON to enable Push Notification";
UIAlertView *alert_push = [[UIAlertView alloc] initWithTitle:@"Push Notification Service Disable" message:msg delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Setting", nil];
alert_push.tag = 2;
[alert_push show];
NSLog(@" Push Notification OFF");
}
}
0
UIUserNotificationType allNotificationTypes =
(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings =
[UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
[[UIAp
折襞sharedApplication] registerUserNotificationSettings:設置];
// [[UIApplicationsharedApplication] registerForRemoteNotifications];
if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)]) {
UIUserNotificationType types = [[[UIApplication sharedApplication] currentUserNotificationSettings] types];
if (types == UIUserNotificationTypeNone) {
[_TransparentView setBackgroundColor:[[UIColor clearColor] colorWithAlphaComponent:0.8]];
[email protected]"Please enable notifications from settings.";
}
}
}
0
試試看看這個代碼。它將在iOS 8.0之後和之前的版本中工作。
if (([[[UIDevice currentDevice] systemVersion] compare:8.0 options:NSNumericSearch] != NSOrderedAscending)) {
if (![[UIApplication sharedApplication] isRegisteredForRemoteNotifications])
{
DisplayAlert(@"Please enable Permission from Settings->App Name->Notifications->Allow Notifications");
return;
}
}
else{
UIRemoteNotificationType status = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (status == UIRemoteNotificationTypeNone)
{
DisplayAlert(@"Please enable Permission from Settings->App Name->Notifications->Allow Notifications");
return;
}
}
相關問題
- 1. iOS:警報通知公式
- 2. 如何設置警報以及通知?
- 3. Phonegap iOS通知警報接受用戶輸入
- 4. 從推送通知的警報視圖啓動應用程序
- 5. 報警通知
- 6. 使用日曆來設置報警通知的Android
- 7. 使用切換按鈕設置報警通知 - Android
- 8. IOS警報查看直接用戶到iPad設置Wifi
- 9. iOS:通知中心的警報問題
- 10. ios:禁用應用程序焦點時的警報通知(OneSignal)
- 11. 定通知警報
- 12. jquery通知警報而不是警報?
- 13. 如何在iOS中延遲一段時間後顯示通知啓用警報?
- 14. 當手機被鎖定時,本地通知警報樣式設置爲「警報」?
- 15. iOS通知顯示兩次默認和我的通知警報
- 16. 如何禁用iOS遠程通知上的默認通知警報視圖?
- 17. 如何在iOS中爲推送通知警報視圖設置操作
- 18. 如何在警報通知中自動啓動應用程序?
- 19. 如何在iOS用戶允許攝像頭訪問警報時得到通知?
- 20. 使用內容Uri報警通知
- 21. 用於HTML的通知警報消息
- 22. 使用php的通知/警報系統
- 23. 報警通知不起作用
- 24. 報警Toast通知窗口metro應用
- 25. 用Kendo通知替換JavaScript警報
- 26. 如何每週從我的應用程序通知用戶警報聲音?
- 27. 如何在Android中設置通知報警
- 28. 設置多個警報/通知錯誤/錯誤?
- 29. 在蔚藍的經典門戶網站上設置通知中心的警報
- 30. 重複報警通知(Android)