I've been trying to find something about this problem for a few days, but without any useful results. I'm working on a VoIP app for iOS (using an iPhone 4 running iOS 6.0) in Objective-c which uses remote notifications to notify the user about calls when the client is in background.
My issue is quite strange: When the app is in background and the screen is locked, notifications arrive and work perfectly - they ring, and open the app when opened. But when the application is in background, and the screen is unlocked - for example, we're on the home screen - notifications simply fail to appear, not giving any sign that something happened.
Anybody got any ideas where to look around? The app code handles push notifications correctly when they appear, so that shouldn't be an issue. The notifications get out of our server, so I'm starting to think that there is something about the device's settings. The app is set to a "banner" alert style, and its notifications are enabled.
When the app is running in the background, the notification does not appear. You need to catch it in the App Delegate application:didReceiveRemoteNotification:.
Implement this method and put a UIAlert to see when the notification arrives.
Related
I am running into a really weird problem where I can't quite nail down the root cause. Our app used to function properly for background/silent notifications for ios12 and ios13 up until a few weeks ago. So a bit of background information:
We use SNS to send visual/audible and silent background notifications.
We are aware of the apns-push-type header that is required for ios13. SNS automatically handles this new header and our manual testing (i.e. without SNS) have also produced the same results.
The silent notifications (i.e. content-available: 1) always fail on ios13.3 (or higher) but always work on ios12.4 (and below).
In our swift code, we are using :didReceiveRemoteNotification:fetchCompletionHandler for silent notifications. We are also using userNotificationCenter (with willPresent and didReceive). Whenever we send audible/visual notifications, willPresent gets triggered on ios12 and ios13. On ios12, silent notifications trigger didReceiveRemoteNotification:fetchCompletionHandler but nothing with ios13.
During our testing, we successfully sent an empty alert type to trigger a silent notification on ios13 and this works on ios12 as well (this triggers willPresent). This feels like a hack to me because it will likely wakeup the device momentarily and the notification will disappear if the app is running in the background.
In other viewcontrollers, we are observing NotificationCenter for received messages to take appropriate actions.
To me it seems, {"content-available": 1} never works on ios13 and but does on ios12. Also didReceiveRemoteNotification:fetchCompletionHandler never gets called on ios13 but does on ios12. Our intent with silent notifications with (i.e. with content-available:1) is to refresh the details from our service when changes occur when the app is in foreground or background.
Any help would be appreciated.
I was able to resolve this issue. Before I get into the solution, however, I want to mention that I ran into this problem only on iOS13 and with silent notifications. The same code was working with iOS12 with same feature.
Our app has a separate screen for requesting notification permissions when the app is launched first time. At this stage we register the device for notifications. Next time when the app is launched, we don't show this screen anymore. To get it to work on ios13, we had to re-register with APNS in AppDelegate's didFinishLaunchingWithOptions every single time. Again, on iOS12 silent notifications were working without re-registering with APNS but on iOS13 we have to re-register every single time.
I hope this helps anyone else running into this problem.
I am writing an alarm clock app for iphone, and I want it to turn on the phone(from standby mode) approx 1hr before the alarm is supposed to go off.
Then I want the app to be active, so I can stream content live without the user having to put the phone in an active-mode.
Any way for an app to switch out of standby?
Without using private api an application can only present alertview (via local or push notification).
And only when user taps "view" button this application can be activated. You can see that in the link you provided - (second to last screenshot)
True, you can always add sound to this notifications - so alarm app can work (and there are many out there) but it can't send itself in the foreground.
Nope that cant be done, once the app went to the background state you lose control on it, and cannot bring it back
There might be a way using notifications. Check this SO question for more info:
Alarm Even Application Closed in iPhone
I have requirement for an application which work in background only.
When first time application install on device then after installation that will be go to background. And after two minutes a view will popup on screen.
Now problem is that after installation how to redirect application into background?
i get answer for this that if we want to send our app into background then we have to open another app like as safari. so i get this solution.
Now problem is that how show a view after two minutes from background. I have to create as a demo not for app store. So if anyone have any solution then suggest me.
Thanks
It is not possible to do so in iOS. You can't send an app into the background
If you want your app to get displayed, the only way to do so is through push (from server) or local (from phone) notifications, and the user has to explicitly accept it.
Unfortunately, you can't make it open automatically.
iOS is not designed to run code in the background. There are a few exceptions, for example a music streaming app, or a GPS navigation app, but in general it cannot be done.
Instead, you should run your app on a server in the cloud, and send a push notification to the phone when you want something to happen on the phone. You may also be able to achieve this with "local notifications", depending on what you're trying to do.
I have an APNS enabled application.
In Iphone4 when user press the HOME button application remains in cache.
Now in this condition when a push notification received after clicking on the VIEW button
the application starts running from the cache!!!.
I have found that it is invoking didReceiveRemoteNotification() and also the state of the application is UIApplicationStateActive rather than UIApplicationStateBackground
But in Iphone 3 it is working fine and invoking didLaunchingWithOptions().
What I want is when the application is not open(currently not running) , if a push notification received it will invoke the handler for push notification and launch the application from start.
any help or guidelines will be highly appriciated .
As far as I know, the application is in SUSPENDED state after tapping home button (after several transitions). So it is not executed (moreover it can be terminated in case system low memory warning).
Your possible solution is to set up the key "Application doesn't run in background" to imitate iOS3 behavior (in your .plist file).
Maybe this link will be useful for you:
iOS 4 backgrounding
If your phone is connected to your MAC and you are debugging then that is the thing that cause your problem, so try disconnect your iphone and try again, that will solve the problem.
I would like to build an app which retrieves images from my server.
My problem is that I want it to work in the background and only when there is a 'new image' to load.
It seems like what I need is very similar to PUSH notifications:
Work in the background
Only when there is 'something new' to load.
I guess what I want became possible with the new iOS4.
Please tell me if this is feasible.
Any links for how to even start thinking about it would be great.
Thanks.
It depends on what background you mean.
If you mean that your application is running and you have some thread to get the image in the background thread, it is possible.
If you mean that your application is suspended and you still want to use PUSH notification and get the image. I am afraid that it is impossible. When your application is in the background, it has very limited amount of time that it can run to finish its current task. When that time is out, your application cannot do anything.
You can receive some push notification and local notification like GPS, server notification when your application is suspended, but you can only receive the server notification and cannot download the new image. Here is the instruction from Apple Dev documentation:
When the operating system delivers a
local or push notification and the
target application is not running in
the foreground, it presents the
notification (alert, icon badge
number, sound). If there is a
notification alert and the user taps
the action button (or moves the action
slider), the application launches and
calls the UIApplicationDelegate method
application:didFinishLaunchingWithOptions:,
passing in the local-notification
object or remote-notification payload.
If the application is running in the
foreground when the notification is
delivered, the
application:didReceiveRemoteNotification:
or
application:didReceiveLocalNotification:
method of the application delegate is
invoked.
More here