Tag: 通知

当本地通知从iOS的通知中心被解除时,什么方法被触发?

我正在尝试创build一个启动本地通知的应用程序,当通知被点击时,应该打开一个特定的viewcontroller 。 我使用didReceiveLocalNotification方法来显示特定的视图控制器。 但是,即使从通知中心解除通知,也正在显示该特定的视图控制器。 当我们closures通知时触发了什么方法? 这是我使用的代码: func application(application: UIApplication!,didReceiveLocalNotification notification: UILocalNotification) { var root = self.window!.rootViewController as ViewController let main: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) var setview = main.instantiateViewControllerWithIdentifier("destination") as tapViewController //root.navigationController?.popToViewController(setview, animated: false) if application.applicationState == UIApplicationState.Inactive { root.presentViewController(setview, animated:false , completion: nil) } }

在多个视图控制器中为一个观察者使用NSNotificationCenterselect器

我可以在多个视图控制器中使用select器getUpdate: 我注册我的LevelViewController作为WinViewController和WinViewController观察员。 后者2视图控制器都有一个后退button(当按下时,它会弹回到LevelVC ),通知的想法是告诉LevelVC是否更新集合视图单元格(通过viewWillAppear:方法)何时后退button被按下。 在viewWillAppear: ,我不想调用两个独立的方法(一个来自GameVC ,另一个来自WinVC ),以获得我的更新,我只是一个可以使用的stream体方法。 这是我打算(在LevelVC ): – (void)viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getUpdate:) name:@"getUpdateForCell" object:nil]; } 并纳入 – (void)getUpdate:(NSNotification *)notification { NSDictionary *data = [notification userInfo]; // pop } 两次…一次在GameVC ,另一次在GameVC中。 这可能吗? 或者我应该只做两个单独的通知?

缺less推送通知权利

提交二进制文件后,我收到了来自Apple的警告邮件。 Missing Push Notification Entitlement – Your app appears to include API used to register with the Apple Push Notification service, but the app signature's entitlements do not include the "aps-environment" entitlement. If your app uses the Apple Push Notification service, make sure your App ID is enabled for Push Notification in the Provisioning Portal, […]

Firebase推送通知操作

我刚刚用swift编写了我的第一个应用程序。Firebase工作良好,我在我的设备上收到通知。 我想要做的是当用户点击通知时设置操作。 我想发送到特定的ProductViewController,具有特定的产品ID(从后端发送)。 如果用户被locking到ProductViewController,则不保留在login屏幕上。 AppDelegate.swift代码: class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, FIRMessagingDelegate { var window: UIWindow? func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) { print(remoteMessage.appData) } func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. let lagFreeField = UITextField() self.window?.addSubview(lagFreeField) lagFreeField.becomeFirstResponder() lagFreeField.resignFirstResponder() lagFreeField.removeFromSuperview() // [START register_for_notifications] if #available(iOS 10.0, […]

NSUbiquityIdentityDidChangeNotification不起作用?

我正在创build一个cloudkit应用程序,并一直在尝试多种方式来获取NSUbiquityIdentityDidChangeNotification ,但我从来没有能够得到这个通知。 我已经尝试了委托didFinish和viewDidLoad方法下的这些代码版本。 我试图从另一个通知 – UIApplicationDidBecomeActiveNotification调用它。 我也把import Foundation放在文件的顶部。 这是我尝试过的基本代码: NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleIdentityChanged:", name: NSUbiquityIdentityDidChangeNotification, object: nil) //这个也是我从另一个post里试过的: var localeChangeObserver = NSNotificationCenter.defaultCenter().addObserverForName(NSUbiquityIdentityDidChangeNotification, object: nil, queue: NSOperationQueue.mainQueue()) { _ in println("The user's iCloud login changed: should refresh all user data.") } 有谁知道如何让这个通知只适用于swift的cloudkit应用程序? 我真的只想检测iCloud状态更改,然后在发生更改时启动获取userID 。 不是我需要访问ubiquityIdentityToken ,但我想知道为什么不存储令牌,每次应用程序开始比较当前令牌和本地存储中的令牌,看看它是不是一个不同的帐户或零? 因此,为什么需要通知? 另外,只有打开“我不需要的iCloud文档”才能获得令牌的代码。 有没有人知道有一个社交应用程序不需要它打开的影响? 还有没有启用iCloud文档获得令牌的另一种方法? 这是我用来获取令牌并放置在委托didFinish方法中的代码,但仅在打开iCloud文档时才有效: var token = NSFileManager.defaultManager().ubiquityIdentityToken println("token is […]

知道iOS通知是否被解雇

有什么方法可以知道本地通知是否被通知中心拒绝(例如通过按下xbutton)? 是否有可能获得通知中心当前可见的所有通知的列表?

UserNotification未显示(iOS 10)

我无法在iOS 10中UserNotification 。我将从我的代码开始: – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; UNAuthorizationOptions options = (UNAuthorizationOptionBadge | UNAuthorizationOptionAlert | UNAuthorizationOptionSound); center.delegate = self; [center requestAuthorizationWithOptions: options completionHandler: ^(BOOL granted, NSError * _Nullable error) { if (granted) { NSLog(@"Granted notifications!"); } }]; // 这工作,我看到日志。 那么,我有: -(void)application: (UIApplication *)application performFetchWithCompletionHandler: (void (^)(UIBackgroundFetchResult))completionHandler { // […]

UIKeyboardWillHide没有被触发

我在这里阅读了很多关于这个主题的文章,但是我没能find我的问题的答案,所以,希望你不会对另一个UIKeyboard文章感到厌烦:-) 在我的视图控制器的实现中,我添加了self作为观察者的两个通知UIKeyboardWillShowNotification和UIKeyboardWillHideNotification ,传递select器keyboardWillShow:和keyboardWillHide:处理通知。 当我触摸一个UITextField , keyboardWillShow:方法被调用,但是当我按下“Done”button(这将closures键盘)时,不会调用keyboardWillHide:方法。 真的,我想让我的UITextField显示一个键盘右下方的“隐藏button”,但我找不到正确的键盘types。 也许我需要将textfield retuntype设置为“…完成”。 这样我看到“返回”键变成了“完成”。 所以我设置了一个工具栏作为我的UITextField的inputAccessoryView ,所以现在我可以使用“完成”button来显示上面的工具栏的标准键盘。 当用户触摸那个button时,我用resignFirstResponder方法隐藏键盘。 奇怪的是,当我呼吁resignFirstResponder , UIKeyboardWillHideNotification不张贴; 至less不调用keyboardWillHide:方法。 你对我有什么build议? 我真的想显示一个键盘与向下箭头的小button隐藏键盘,但也是这个解决scheme可能是正确的,但我想调整视图,并做到这一点,我需要观察员UIKeyboardWillHideNotification 。 非常感谢你的帮助… (添加:) 在viewDidLoad : [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:[[self view] window]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:[[self view] window]]; 我把这些声明从“你的”之一发布:-)但willShow的作品… UIToolbar中被指定为我的文本字段的inputAccessoryView的“完成”button的操作是: -(void)keyboardDone { [msgTextField resignFirstResponder]; closures:OK! 当一个开发者是愚蠢的…这是愚蠢的:-) 🙂 这是我更正的willHide方法: -(void)keyboardWillHide:(NSNotification*)n { NSDictionary* userInfo; CGSize […]

检查UILocalNotification弃用后是否启用用户通知

在我的应用程序中,我希望能够检查用户是否启用了通知。 在iOS 10中,我在代理中使用了一个检查。 这个检查现在已经过时,我想更新它,但我不知道在iOS 11中使用什么。 弃用警告如下: currentUserNotificationSettings'已被弃用在iOS 10.0:使用UserNotifications框架的 – [UNUserNotificationCenter getNotificationSettingsWithCompletionHandler:]和 – [UNUserNotificationCenter getNotificationCategoriesWithCompletionHandler:] 我试图用这个警告的帮助来更新代码,但我无法弄清楚。 如果任何人都可以build议这样的工作,这将有助于很多。 我一直在使用iOS 10的代码如下,谢谢。 let notificationType = UIApplication.shared.currentUserNotificationSettings!.types if notificationType == [] { print("Notifications are NOT enabled") } else { print("Notifications are enabled") }

如何在应用程序处于前台时显示本地通知

如何显示本地通知,即使在前台,使用新的(从iOS 10)通知框架UserNotifications https://developer.apple.com/reference/usernotifications?language=objc ?