Force touch the app icon when app closed from task manager - ios

while using quick actions of 3D Touch it works good but while app is terminated first time force touch the app icon it open home screen but the other times it open the right screen.
why this happen and how I can test the app while it is terminated

From the method application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) you can use the launchOptions argument to detect whether user is launching the app by pressing shortcut item key or not.
if launchOptions != nil {
if let userInfo = launchOptions![UIApplicationLaunchOptionsShortcutItemKey] {
//Handled the implementation here
}
}

Related

Terminated App only being restarted one time

I have an application that by design should be activated by the OS after a location event is delivered from the system even if the app has been terminated. Terminated can mean terminated by the system or by the user in the multitasking switcher. My app delegate code is below and the location delegate is an extension of the app delegate class. The first event that is generated by the system after the app is terminated is delivered to my app and processed properly, but I am not receiving any subsequent events. Is there some code I need to run after the event is received to reregister my application for future updates?
var window: UIWindow?
var locationManager: CLLocationManager!
var notificationCenter: UNUserNotificationCenter?
var today:String? //Today's date format: YYYY-MM-DD
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if launchOptions?[UIApplicationLaunchOptionsKey.location] != nil {
self.locationManager = CLLocationManager()
self.locationManager.delegate = self
self.locationManager.requestAlwaysAuthorization()
self.locationManager.startMonitoringVisits()
self.locationManager.allowsBackgroundLocationUpdates = true
sendTestNotification()
} else {
print("normal launch")
}
You say your app has been "terminated". This suggests that you kill your app intentionally as a way of testing. But if an app has been forcibly terminated, the system deliberately stops background location monitoring, so naturally you won't get any more visit monitoring events. It is as if you had called stopMonitoringVisits yourself.
app terminate is not allow by apple as i know.
exit(0)
you can use that code line to app terminate

SKStoreReviewController is being displayed the first time user launches the app

In my iOS app I'm using SKStoreReviewController to request users to rate the app. The Apple documentation says to put the code for requesting the "Rate Us" popup anywhere we want, and they will govern when it will be actually displayed.
I wrote the following code in the first view of the app:
func requestReview() {
SKStoreReviewController.requestReview()
}
The problem is that the popup is displayed to my app's users as soon as they first launch the app, which makes no sense. Is there any way to control the popup's appearance and avoid showing it before certain amount of uses of the app?
SKStoreReviewController.requestReview() will display the popup for the first few times (to be exact, for the first 3 times in a year).
Create a variable that you increment each time in your application delegate's didFinishLaunchingWithOptions method and save it to UserDefaults. After that, you can check whether a user opened the app enough times.
AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
var appLaunches = UserDefaults.standard.integer(forKey: "appLaunches")
appLaunches += 1
UserDefaults.standard.set(appLaunches, forKey: "appLaunches")
return true
}
The view controller where you want to display the store review controller
let appLaunches = UserDefaults.standard.integer(forKey: "appLaunches")
if appLaunches >= [enough number of app launches] {
SKStoreReviewController.requestReview()
}

iOS: apple universal link if app is not open?

My app can successfully handle apple universal links, if the app is already open (backgrounded). But if the app is not open already, then when I tap such a link in, say, mail, the app opens, but I never get the callback for application:continueUserActivity... (which I do if the app was already open/backgrounded)...
To wit:
If the app is backgrounded, and I click on an apple universal link in, say, the mail app, then this method (which is what apple's documentation says to implement to handle universal links):
optional func application(_ application: UIApplication,
continueUserActivity userActivity: NSUserActivity,
restorationHandler restorationHandler: ([AnyObject]?) -> Void) -> Bool
Gets called. If the app is not running (I force close it), then when I click on the link, that method does NOT get called, but the app DOES open.
Is this supposed to work this way?
Based MCMatan's clue, you have to do something like this in didFinishLaunchingWithOptions, and then continueUserActivity will get called:
if let userActivityDict = launchOptions?[UIApplicationLaunchOptionsUserActivityDictionaryKey] as? NSDictionary,
activityType = userActivityDict[UIApplicationLaunchOptionsUserActivityTypeKey] as? String where activityType == NSUserActivityTypeBrowsingWeb {
return true
}
You are correct. If the app is not in background "continueUserActivity" will not be called.
Instead, application:didFinishLaunchingWithOptions will call with the information:
let activityDic = launchOptions?[UIApplicationLaunchOptionsUserActivityDictionaryKey]
if let isActivityDic = activityDic {
// Continue activity here
}

CLCircularRegion and wake up app

In application we have mechanism like native Reminder app in iOS with firing notifications when user enter or exit in some region.
But two devices behave differently (5 and 5s) in same time. All devices have enable notifications, and allow use locations.
Two devices have a some "travel" and in the route created 10 points. First device (5) when came to finish received only 6 notifications, (5s) don't receive any notification.
But my question is how I can know when my app is restart in background or continue working. Because, all log in app I redirect into a file, and after download container and analyze what happened in app in travel time.
I noticed app restart in same times when device is enter to region and my log marks fired in the file but notifications don't receive. This is happended when app try to get some information from web service in didFinishLaunchingWithOptions
And maybe this is problem. How to know distinguish restart app or continue working. Thx.
Are you checking UIApplicationLaunchOptionsLocationKey in didFinishLaunchingWithOptions similar to (sorry, Swift is what I have now):
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if launchOptions?[UIApplicationLaunchOptionsLocationKey] != nil {
// app was launched in response to incoming location event
}
}
Additionally, if you're not already doing this you may need to create notifications differently if app is in background:
// Show an alert if application is active
if UIApplication.sharedApplication().applicationState == .Active {
if let message = notefromRegionIdentifier(region.identifier) {
if let viewController = window?.rootViewController {
showSimpleAlertWithTitle(nil, message: message, viewController: viewController)
}
}
}
else {
// Otherwise present a local notification:
let notification = UILocalNotification()
notification.alertBody = notefromRegionIdentifier(region.identifier)
notification.soundName = "Default";
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
}

What is actually the value of UIApplicationBackgroundFetchIntervalMinimum?

I'm about setting up background fetch for an iOS application.
I do:
func application(
application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?
) -> Bool {
...
application.setMinimumBackgroundFetchInterval(
UIApplicationBackgroundFetchIntervalMinimum)
...
if I inspect and print UIApplicationBackgroundFetchIntervalMinimum in the debugger it says 0 - what is the value actually ?
I tried looking through the api as well but no luck https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/#//apple_ref/occ/instm/UIApplication/setMinimumBackgroundFetchInterval:
It is not specified by Apple how long UIApplicationBackgroundFetchIntervalMinimum time is, however in practice it is around 10 minutes.

Resources