खोज…


परिचय

AppDelegate एक प्रोटोकॉल है जो एक ऐप के जीवनकाल में महत्वपूर्ण घटनाओं के जवाब में सिंगलटन UIApplication ऑब्जेक्ट द्वारा कहा जाता है कि तरीकों को परिभाषित करता है।

आम तौर पर एप्लिकेशन स्टार्टअप (सेटअप ऐप पर्यावरण, एनालिटिक्स (उदा .: मिक्सपेनल / गूगलएनालिटिक्स / क्रैशलाइक्स), डीबी स्टैक आदि) और शटडाउन (पूर्व: डीबी संदर्भ सहेजें), यूआरएल ओपन अनुरोधों को संभालने और इसी तरह के एप्लिकेशन-वाइड पर कार्य करने के लिए उपयोग किया जाता है। कार्य।

AppDelegate तरीकों के माध्यम से आवेदन के सभी राज्यों

अद्यतित होने के लिए या ऐप से पहले कुछ करने के लिए उपयोगकर्ता के लिए लाइव आप नीचे विधि का उपयोग कर सकते हैं।

AppDidFinishLaunching

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Write your code before app launch
    return YES;
}

जबकि ऐप फॉरग्राउंड में दर्ज करें:

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

जब ऐप लॉन्चिंग और बैकग्राउंड भी बैकग्राउंड हिट हो तो विधि:

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

जबकि ऐप पृष्ठभूमि में दर्ज करें:

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

जबकि ऐप सक्रिय इस्तीफा दे

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

जबकि एप्लिकेशन समाप्त:

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

AppDelegate भूमिकाएँ:

  • AppDelegate में आपके ऐप का startup code
  • यह आपके ऐप की state में key changes जवाब देता है। विशेष रूप से, यह दोनों अस्थायी रुकावटों का जवाब देता है और आपके ऐप के निष्पादन की स्थिति में परिवर्तन करता है, जैसे कि जब आपका ऐप अग्रभूमि से पृष्ठभूमि पर स्थानांतरित होता है।
  • यह ऐप के बाहर से आने वाली responds to notifications , जैसे कि रिमोट नोटिफिकेशन (पुश नोटिफिकेशन के रूप में भी जाना जाता है), कम-मेमोरी चेतावनियां, पूरा होने वाले नोटिफिकेशन को डाउनलोड करें, आदि।
  • यह determines कि क्या state preservation और restoration होनी चाहिए और आवश्यकतानुसार संरक्षण और बहाली प्रक्रिया में सहायता करती है।
  • यह responds to events जो एप्लिकेशन को स्वयं लक्षित करते हैं और आपके ऐप के विचारों या व्यू कंट्रोलर के लिए विशिष्ट नहीं हैं। आप इसका उपयोग अपने ऐप की केंद्रीय डेटा ऑब्जेक्ट या ऐसी किसी भी सामग्री को संग्रहीत करने के लिए कर सकते हैं, जिसमें एक स्वामित्व दृश्य नियंत्रक नहीं है।

URL-Specified संसाधन खोलना

प्रतिनिधि को एक URL द्वारा निर्दिष्ट संसाधन खोलने के लिए कहता है, और लॉन्च विकल्पों का एक शब्दकोश प्रदान करता है।

उपयोग का उदाहरण:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        return SomeManager.shared.handle(
            url,
            sourceApplication: options[.sourceApplication] as? String,
            annotation: options[.annotation]
        )
    }

स्थानीय और दूरस्थ सूचनाओं को संभालना

उपयोग का उदाहरण:

/* Instance of your custom APNs/local notification manager */  
private var pushManager: AppleNotificationManager!

पंजीकरण:

func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
    // Called to tell the delegate the types of notifications that can be used to get the user’s attention
    pushManager.didRegisterSettings(notificationSettings)
}

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
    // Tells the delegate that the app successfully registered with Apple Push Notification service (APNs)
    pushManager.didRegisterDeviceToken(deviceToken)
}

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
    // Sent to the delegate when Apple Push Notification service cannot successfully complete the registration process.
    pushManager.didFailToRegisterDeviceToken(error)
}

दूरस्थ सूचनाओं को संभालना:

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    // Remote notification arrived, there is data to be fetched
    // Handling it
    pushManager.handleNotification(userInfo,
                                   background: application.applicationState == .Background
    )
}

स्थानीय सूचनाओं को संभालना:

func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
    pushManager.handleLocalNotification(notification, background: false)
}

हैंडलिंग कार्रवाई (पदावनत):

func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [NSObject : AnyObject],
                     completionHandler: () -> Void) {
    pushManager.handleInteractiveRemoteNotification(userInfo, actionIdentifier: identifier, completion: completionHandler)
}


Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow