Which alert would be displayed if there're many competing alerts? - ios

In iOS, many alerts can occur at a time in practice.
For example, if you're requesting a Photo Album (or whatever) permission, OS will present an alert. At a same time, programmer can UIViewcontroller.present() an UIAlertController instance as at their will.
What alert would be chosen at first place in this case?

I don't know the internal implementation, but according to my experiment on iOS 10.1.1 real device, alerts are shown in this order.
System alerts. Alerts that presented by operating system itself. (such as Photo Album permission request) This is the highest priority. If any of this alert gets presented, any other in-app alerts will be hidden temporarily, and shown again after end-user make a choice on the system alert. Priority between system alerts are unknown.
Your in-app alert. You can present only one in-app alert at a time because you are supposed to use UIViewController.present method to present an alert in current version of iOS. And this method will use your nearest presentation-context VC or root VC of its window. In either case, Apple is actually enforcing you to present only one alert at a time, and control presentation priority of the alerts yourself.

Related

iOS Push Notification with Rich Content - Can I prevent a notification from being tappable?

I have a push notification with rich content.
Can I make it in such way that it is not tappable, i.e., a single tap will not open the application. It must be dragged down to rich content or 3D touched, or deleted from the notification center by swiping.
How should I indicate to the user to drag down (3D touch) in order to reveal rich content on notification?
No, a tap on a push notification will always open the notification in the app, and as far as I know there is no way in public API to override this behavior. It does appear there is a private API to get the behavior you’re looking for, as some iOS-generated (local, not push) notifications appear to do exactly what you’re asking. If you can manage to uncover that, use at your own risk should Apple find out.
Now, as for possible solutions: I would consider implementing code on your app’s delegate to respond appropriately when the notification is opened. For example, send the user to an appropriate location in the app when the app is launched from a notification…perhaps a view controller that shows the same content that would be shown as the rich notification content. I don’t know the exact use case, but the wording implies to me that if the app launches to its main interface, it could be confusing to a user.
It’s impossible for me to tell you how exactly you wish to respond to notifications, so for more on responding appropriately when the app was launched from a push notification, see the following documentation from Apple:
Determine Why Your App Was Launched
UIApplicationDelegate.application(_:willFinishLaunchingWithOptions:)
UIApplicationDelegate.application(_:didFinishLaunchingWithOptions:)
UIApplication.LaunchOptionsKey
UIApplication.LaunchOptionsKey.remoteNotification
Hopefully from that you can find a suitable solution. But if that isn’t an option, consider directly telling the user at some point to press firmly (or tap and hold, as many devices do not support 3D Touch) to view the content. You could do this during some onboarding process or, as an absolute last resort, in the notification itself.
Before proceeding down that route, though, understand that not all users know 3D Touch and/or this rich-content functionality even exists — even fewer use it regularly — and if they become confused, they may decide to clear the notification or outright disable your app’s notifications. In general, it’s also a bad idea to “teach” your user unfamiliar ways of using their device. If a user is used to tapping on notifications, as many are, they will most likely tap on your notifications. It can be tough to break that muscle memory.

How can i check what user did with SKStoreReviewController modal?

I have a few questions i could not find an answer to.
Can we find out if user tapped cancel/submit?
Can we know if user already give review? (To not show him modal again)
If user give a review and method to show review modal is called will it appear?
No
Apple handles that
No
You can read more about it here.
I include a link to a similar answer I posted that helps provide some insight into how the view is presented if you'd like to see the technical side.
SKStoreReviewController buttons hidden under keyboard
This answer goes into detail about the presentation of the view as well which may be of interest (how often it is shown, when it is not shown, etc)
Why the SKStoreReviewController does not let me submit a review?
Here's an idea. Not tested, but feel free if you have any other ones.
When you decide to run: SKStoreReviewController.requestReview() so the user is prompted with the native "Rate in the app store",
Set and control a timer.
Then in the appdelegate/applicationWillEnterForeground control this timer:
- If the user selected "submit", the app will probably go to background within the next 5 to 10 seconds. So if the app hit this method and the elapsed time is less than (i.e) 10 seconds, than (probably) means that the user went to the Apple Store.
- Meanwhile, if the timer hits 30 seconds, stop the timer and save your guess: The user didn't submit the review.
Also, many apps present a custom popup asking the user if they like the app and if so then they present the native SKStoreReviewController.requestReview()

Determine which button was tapped on system alert

I am presenting SKStoreReviewController.requestReview() and I want to have a boolean in UserDefaults which I would make true in case the user taps on Cancel.
Is there a way to determine if cancel was tapped considering this is a OS alert?
There isn’t a way to access which button was selected. I’m curious why you would you need this functionality? The OS will decide if the user should be shown the alert depending on a few factors including when the user last left a review or canceled.
Apple Developer Site:
https://developer.apple.com/documentation/storekit/skstorereviewcontroller/2851536-requestreview
Although you should call this method when it makes sense in the user
experience flow of your app, the actual display of a rating/review
request view is governed by App Store policy. Because this method may
or may not present an alert, it's not appropriate to call it in
response to a button tap or other user action.

Is it possible to change the display duration of a UILocalNotification?

I need to display a local notification and have it remain on screen longer than the default 4-5 seconds, preferably until the app itself removes it. I've seen other apps (e.g. Pandora) that manage to do this somehow (maybe a push notification?), but I can find no duration property on UILocalNotification or in UIApplication methods like presentLocalNotificationNow:, scheduleLocalNotification:, etc. Neither the documentation nor any of the tutorials I've found address the display time at all. Is this something that just can't be done with local notifications?
A couple of solutions here and I would not recommend either:
1- You can request from the user to go to settings > Notification Center > your app. And change the alert style from Banner (default) to Alerts. This will present the user an alert similar to the alert presented when the app is in the foreground. The user would have to dismiss the alert versus the banner style notification that just appears/disappears. Unless this is a corporate app and you have the users buy in, I would not go that route as this could annoy the user.
2- I tested the sound clip method and yes, if you present a notification with a clip < 30seconds; the notification will stay on the (top of the) screen until the sound clip is finished playing. Having said that, if the user taps any of the volume button (to reduce the sound for example), the notification is immediately dismissed even before its end! I think though that the purpose of the notification is a gentle reminder and, lasting more than the typical 4-5 seconds goes against the norm and, it might annoy the user (or the user might think something is stuck, phone froze, etc..). Here is the code anyway:
UILocalNotification *howLongCanANotificationLast = [[UILocalNotification alloc]init];
howLongCanANotificationLast.alertBody=#"I am a notification";
howLongCanANotificationLast.soundName=#"musicfilename.mp3";
[[UIApplication sharedApplication] presentLocalNotificationNow:howLongCanANotificationLast];
Hope this helps.

How can I edit the pairing alert view

I am developing an iOS 6 app that pairs with a custom BLE device.
When the user wants to pair, an alert message appears (directly form core bluetooth I guess) and the user can either push "Pair" or "Cancel".
However the title and body of the alert message are empty showing "PAIRING_TITLE" and "PAIRING_BODY".
How can I write a specific content for these two variables? Any idea?
As you guessed, that alert view is shown by the system and cannot be customized. I suppose it is the simulator that is causing those messages to be shown instead of some meaningful text. This can never happen on an actual device. Recommendation from Apple is not to use the simulator for development of BLE stuff. It is very likely that it won't be possible in the near future anyway.

Resources