notificationcenter

How to call a function when the app is inactive (e.g. playing music in background)?

时光毁灭记忆、已成空白 提交于 2020-04-07 08:25:29
问题 I am making a music-streaming alarm clock. Music streams for the duration selected by the user, including in the background, and at the end of the duration a custom alarm sound is played in addition to a local notification. In short (1) set timer (2) local notification fires off (3) streamed music stops (4) alarm plays I am able to do (1) and (2) ok, but am unable to figure out how to trigger (3) or (4) when the app is in the background. Here is the code for (1) and (2) let center =

How to programmatically read incoming text messages on iOS

流过昼夜 提交于 2020-02-20 07:40:26
问题 There have been tons of questions on how to programmatically access the SMS messages stored in the iPhone. Doing a small research you will quickly and sadly find out that Apple won't let us developers touch the SMS API or SMS database due to obvious security reasons. Let's set this fact apart for a moment. I own a BMW car that comes equipped with a fantastic "infotainment" system called iDrive. Just recently I realized that I could actually read incoming text messages through the iDrive

NotificationCenter: Toggling keyboard multiple times sets y-position to weird value

岁酱吖の 提交于 2020-01-25 06:44:32
问题 I've got a UIViewController with a UITableView. I'm using NotificationCenter to set the y-coordinates for the view to adjust when the keyboard shows and hides again. For the first show + hide, everything looks fine. Doing it a second time messes up things on the screen. I've included print statements in the show / hide actions to get to the bottom of it - see below. class ChatDetailViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet weak var UserLogo:

NotificationCenter: Toggling keyboard multiple times sets y-position to weird value

前提是你 提交于 2020-01-25 06:44:28
问题 I've got a UIViewController with a UITableView. I'm using NotificationCenter to set the y-coordinates for the view to adjust when the keyboard shows and hides again. For the first show + hide, everything looks fine. Doing it a second time messes up things on the screen. I've included print statements in the show / hide actions to get to the bottom of it - see below. class ChatDetailViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet weak var UserLogo:

get a notification from notificationCenter after returning from a phone call

倾然丶 夕夏残阳落幕 提交于 2020-01-11 03:56:17
问题 I want to do an action after the user tapped on the call button and made a call then returned to the app. This is my function for making a phone call : let phoneURL = URL(string: String(format: "tel://%@", phoneNumber.englishNumbers)) UIApplication.shared.open(phoneURL!) and I have set an observer on CallView in viewDidLoad() like this: NotificationCenter.default.addObserver(self, selector: #selector (showFeedBack), name: UIApplication.didEnterBackgroundNotification, object: nil) After I made

Not getting screenLock notification on Swift 4 on mac

不问归期 提交于 2020-01-06 06:30:19
问题 For some reason I'm not getting the ScreenIsLocked and ScreenIsUnlocked notifications. I defined that the screen get locked 0 seconds after the screen saver starts and yet no log: import Cocoa @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { @objc func screenLocked() { NSLog("yes") } func applicationDidFinishLaunching(_ aNotification: Notification) { // Insert code here to initialize your application NotificationCenter.default.addObserver( self, selector: #selector

How do we detect when control center on iOS 7?

笑着哭i 提交于 2020-01-04 08:26:18
问题 I am having an issue when the control center appears on iOS 7. Basically, the applicationDidEnterBackground is fired when the control center appears. However in my method, I would like to detect if it's just the control center opening or the notification center since I would treat the applicationDidEnterBackground differently in that state. Any help would be appreciated. 回答1: I just published a little UIWindow subclass that does exactly that. You simply subscribe to an NSNotification and can

iOS push notifications of other apps

徘徊边缘 提交于 2019-12-30 11:34:08
问题 Is there a way of receiving all the push notifications of all apps? So all notifications being displayed in the notification center? If yes, is it also possible to perform an action when any push notification from any app is received? Thanks EDIT: It is not important if the app will be accepted by Apple. 回答1: Push notifications are dispatched to the app that registered to receive them. You cannot access all notifications, so the short answer would be no . 回答2: No, this is not possible.

Removing a notification from notification center on click

删除回忆录丶 提交于 2019-12-29 04:21:25
问题 Is it possible to remove the push notification from the notification center when one is clicked and the app launches? Most apps seem to leave the notification in place. I read on another question that this: [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; may work however it doesn't work for me. The Facebook app definitely seems to remove the push notifications once clicked on. 回答1: int badgeCount = [UIApplication sharedApplication].applicationIconBadgeNumber; [

iOS - NotificationCenter addObserver “UIMenuControllerWillHideMenu”

你。 提交于 2019-12-25 11:16:09
问题 I have added notification observer for UIMenuControllerWillHideMenu but it does not call selector added/associated with notification center. UIMenuControllerWillHideMenu is notification center identifier for UIMenuController and should be called when UIMenuController will hide. But somehow it's not working. Here is code I've tried (Swift 3.x): private func addMenuObserverNotification(){ NotificationCenter.default.addObserver(self, selector: #selector(self.menuControllerWillHideMenu), name: