मैं एक सामान्य इसी तरह की समस्याओं विभिन्न लांच विकल्प का पता लगाने ((चल रहा है कैसे हमारे अनुप्रयोग सक्रिय अवस्था में है))
स्विफ्ट 2 हल करने के लिए संबंधित समाधान सुझाव है।3
AppDelegate में
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if let options = launchOptions{
print(options.description)
//These options will give the difference between launching from background or from pressing the back button
if (launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] != nil) {
//this indicates the app is launched by pressing Push notifications
}else if (launchOptions?[UIApplicationLaunchOptionsLocalNotificationKey] != nil) {
//This indicates the app is launched on tapping the local notifications
}else if (launchOptions?[UIApplicationLaunchOptionsSourceApplicationKey] != nil){
//This indicates the App launched from a valid source e.g: on tap of Open App from App Store when your App is installed or directly from home screen
}
}
}
संदर्भ: एप्पल डॉक्स सभी उपलब्ध लांच विकल्प जो जोड़कर
https://developer.apple.com/documentation/uikit/uiapplicationdelegate/launch_options_keys
पता लगाया जा सकता प्रतिनिधि प्रोटोकॉल विधियों की शक्ति का उपयोग करें प्रदान पर्यवेक्षक
https://developer.apple.com/documentation/uikit/uiapplicationdelegate
स्विफ्ट 3 समतुल्य:
//adding observer
NotificationCenter.default.addObserver(self,
selector: #selector(applicationDidBecomeActive),
name: .UIApplicationDidBecomeActive,
object: nil)
//removing observer
NotificationCenter.default.removeObserver(self,
name: .UIApplicationDidBecomeActive,
object: nil)
// callback
func applicationDidBecomeActive() {
// handle event
}
Stackoverflow में इसी प्रकार के प्रश्न जो मेरे आप मदद आउट:
Detect when "back to app" is pressed
How to detect user returned to your app in iOS 9 new back link feature?
Detect if the app was launched/opened from a push notification
Checking launchOptions in Swift 3
स्रोत
2017-06-27 14:02:16
देख https://stackoverflow.com/questions/13447101/bring-previous-app-back-to-the-front-when-user-is-done-with-my-ios -एप – Burnie777
यदि आप "प्रोग्राम स्क्रीन पर उपयोगकर्ता को प्रोग्रामेटिक रूप से भेज रहे हैं", तो क्या आप बस इससे पहले अपने ऐप में ध्वज सेट नहीं कर पाए? फिर 'applicationDidBecomeActive' में, इसके लिए जांचें। – dfd
@dfd उपयोगकर्ता तब सेटिंग छोड़ सकते हैं और किसी भी समय बाद में ऐप पर वापस जा सकते हैं। फिर ध्वज अभी भी सत्य पर सेट है, जबकि यह अब – user3581248