I am sending Push Notifications to my iPhone app, and I'd like a different set of instructions to execute depending on whether the app is already launched or not. I'm new to iPhone development, and while I suspect UIApplication or my project's AppDelegate class has the solution, I haven't found a good answer. Is there an easy way to check for this?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Plugin with id 'com.google.gms.google-services
- How can I implement password recovery in an iPhone
- google-drive can't get push notifications
相关文章
- Could I create “Call” button in HTML 5 IPhone appl
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Open iOS 11 Files app via URL Scheme or some other
- Can keyboard of type UIKeyboardTypeNamePhonePad be
- Can not export audiofiles via “open in:” from Voic
The Apple documentation for push notifications explains this:
This means that if your application:didReceiveRemoteNotification: delegate method is called, your app is running.
The UIApplication delegate has the method
which you need to implement. This receives the notification when the app is running.
If your app is not currently running and a notification is received then your app can be launched with
with the notification details held in the launchOptions dictionary. if the dictionary is nil then the user tapped the application icon as normal.
didReceiveRemoteNotification:
is called when the app is running, yes, but when it is suspended, theiOS
takes care of putting up the badge, etc. If the app is in the foreground, the OS does nothing, and just calls yourdidReceiveRemoteNotification:
.Depending upon what you mean by "launched", you are either looking for:
Use a flag that is set true when the application becomes active, and false when the application is not active.
Flag (in header file [.h]):
Code (in implementation file [.m]):
This works because when the application is suspended, the OS calls "applicationDidReceiveRemoteNotification" before it calls "applicationDidBecomeActive" during the "wake-up" process.
The "complete" answer is actually Kevin's answer plus this answer.
Hope this helps.
If you are going to check applicationState on iOS less than 4, you'll need to check that applicationState is supported: