{"id":3489,"date":"2021-07-16T14:10:36","date_gmt":"2021-07-16T06:10:36","guid":{"rendered":"http:\/\/123.57.164.21\/?p=3489"},"modified":"2021-07-16T14:10:36","modified_gmt":"2021-07-16T06:10:36","slug":"swift-%e8%ae%a9%e7%a8%8b%e5%ba%8f%e6%8c%82%e8%b5%b7%e5%90%8e%ef%bc%8c%e8%83%bd%e5%9c%a8%e5%90%8e%e5%8f%b0%e7%bb%a7%e7%bb%ad%e8%bf%90%e8%a1%8c%e4%bb%bb%e5%8a%a1","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=3489","title":{"rendered":"Swift &#8211; \u8ba9\u7a0b\u5e8f\u6302\u8d77\u540e\uff0c\u80fd\u5728\u540e\u53f0\u7ee7\u7eed\u8fd0\u884c\u4efb\u52a1"},"content":{"rendered":"\n<p><strong>1\uff0c\u7a0b\u5e8f\u7684\u6302\u8d77\u548c\u9000\u51fa<\/strong><\/p>\n\n\n\n<p>\u7531\u4e8eiOS\u8bbe\u5907\u8d44\u6e90\u6709\u9650\u3002\u5f53\u7528\u6237\u70b9\u51fb\u4e86home\u952e\uff0c\u6216\u8005\u53e6\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u4e86\u3002\u90a3\u4e48\u539f\u5148\u90a3\u4e2a\u7a0b\u5e8f\u4fbf\u8fdb\u5165\u540e\u53f0\u88ab\u6302\u8d77\uff0c\u4e0d\u662f\u9000\u51fa\uff0c\u53ea\u662f\u505c\u6b62\u6267\u884c\u4ee3\u7801\uff0c\u540c\u65f6\u5b83\u7684\u5185\u5b58\u88ab\u9501\u5b9a\u3002\u5f53\u5e94\u7528\u7a0b\u5e8f\u6062\u590d\u65f6\uff0c\u5b83\u4f1a\u4ece\u505c\u6b62\u7684\u4f4d\u7f6e\u91cd\u65b0\u5f00\u59cb\u3002<\/p>\n\n\n\n<p><strong>2\uff0c\u5982\u4e0b\u7279\u6b8a\u7684\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u5728\u540e\u53f0\u957f\u65f6\u95f4\u7684\u8fd0\u884c<\/strong><\/p>\n\n\n\n<ul><li>\uff081\uff09\u5728\u540e\u53f0\u64ad\u653e\u97f3\u9891\u7684\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u5728\u4efb\u610f\u957f\u7684\u65f6\u95f4\u5185\u4fdd\u6301\u6d3b\u52a8\u72b6\u6001\uff0c\u76f4\u5230\u7528\u6237\u5f00\u59cb\u4ece\u53e6\u4e00\u4e2aApp\u64ad\u653e\u97f3\u4e50\u4e3a\u6b62\u3002<\/li><li>\uff082\uff09\u5728\u540e\u53f0\u8ddf\u8e2a\u7528\u6237\u4f4d\u7f6e\u7684\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u8fd0\u884c\u4efb\u610f\u957f\u7684\u65f6\u95f4\u3002<\/li><li>\uff083\uff09\u8bf8\u5982Skype\u4e4b\u7c7b\u7684\u7f51\u7edc\u534f\u8bae\u7535\u8bdd\uff08VoIP\uff09\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u5b9a\u671f\u8fd0\u884c\uff0c\u4ee5\u5411\u670d\u52a1\u5668\u7b7e\u5230\uff0c\u4f46\u9664\u975e\u6b63\u5728\u8fdb\u884c\u901a\u8bdd\uff0c\u5426\u5219\u4e0d\u5141\u8bb8\u4e0d\u52a0\u9650\u5236\u5730\u8fd0\u884c\u3002<\/li><\/ul>\n\n\n\n<p><strong>3\uff0c\u7533\u8bf7\u7a0b\u5e8f\u5728\u540e\u53f0\u77ed\u65f6\u8fd0\u884c<\/strong><\/p>\n\n\n\n<ul><li>\uff081\uff09\u9664\u4e86\u4e0a\u8ff0\u7684\u7279\u6b8a\u5e94\u7528\uff0cApp\u8fdb\u5165\u540e\u53f0\u65f6\u4fbf\u81ea\u52a8\u6302\u8d77\u3002\u4f46\u6211\u4eec\u53ef\u4ee5\u7533\u8bf7\u8be5\u5e94\u7528\u5728\u540e\u53f0\u80fd\u77ed\u65f6\u95f4\u8fd0\u884c\u3002\u4f46\u8fd9\u4e2a\u65f6\u957f\u4e0d\u80fd\u8d85\u8fc710\u5206\u949f\u3002<\/li><li>\uff082\uff09\u540e\u53f0\u77ed\u65f6\u8fd0\u884c\u7684\u5b58\u5728\u662f\u4e3a\u4e86\u8ba9\u5e94\u7528\u7a0b\u5e8f\u80fd\u591f\u5b8c\u6210\u4e00\u4e2a\u9700\u8981\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u8fc7\u7a0b\u3002\u6bd4\u5982\u5c06\u5927\u578b\u6587\u4ef6\u5199\u4f1a\u78c1\u76d8\uff0c\u5b8c\u6210\u4e0b\u8f7d\uff0c\u6216\u8005\u50cf\u5373\u65f6\u901a\u8baf\u8f6f\u4ef6\u7ed9\u5bf9\u65b9\u53d1\u7167\u7247\uff08\u9009\u62e9\u53d1\u9001\u540e\uff0c\u5373\u4f7f\u8fdb\u5165\u540e\u53f0\uff0c\u4e5f\u80fd\u7ee7\u7eed\u53d1\u9001\uff09\u3002<\/li><li>\uff083\uff09\u572810\u5206\u949f\u7ed3\u675f\u65f6\uff0c\u5e94\u7528\u7a0b\u5e8f\u5fc5\u987b\u544a\u8bc9OS\uff0c\u5b83\u5df2\u7ecf\u5b8c\u6210\u6216\u8005\u88ab\u7ec8\u6b62\u3002<\/li><li>\uff084\uff09\u6ce8\u610f\uff1a\u5e76\u4e0d\u80fd\u4fdd\u8bc1\u7528\u4e8e\u540e\u53f0\u4efb\u52a1\u7684\u989d\u5916\u65f6\u95f4\u662f\u8fde\u7eed\u7684\uff0c\u8fd9\u4e9b\u65f6\u95f4\u53ef\u80fd\u4f1a\u88ab\u5206\u4e3a\u5f88\u591a\u6bb5\uff0c\u4ee5\u5ef6\u957f\u7535\u6c60\u5bff\u547d\u3002<\/li><\/ul>\n\n\n\n<p><strong>4\uff0c\u901a\u8fc7\u6837\u4f8b\u6f14\u793a\u5982\u4f55\u5728\u540e\u53f0\u8fd0\u884c\u4efb\u52a1<\/strong><\/p>\n\n\n\n<p>\u4e3b\u9875\u9762\u4e0a\u901a\u8fc7\u5b9a\u65f6\u5668\u4e0d\u65ad\u7684\u6253\u5370\u51fa\u6570\u5b57\u3002\u8fd8\u6709\u4e2a\u5f00\u5173\u6309\u94ae\uff0c\u5207\u6362\u9009\u62e9\u7a0b\u5e8f\u8fdb\u5165\u540e\u53f0\u540e\u662f\u5426\u7ee7\u7eed\u8fd0\u884c\u3002\u5f00\u5173\u5f00\u542f\u65f6\uff0c\u6309home\u952e\u9000\u51fa\u5e94\u7528\uff0c\u8fc7\u4e00\u4f1a\u513f\u518d\u56de\u6765\uff0c\u53ef\u4ee5\u53d1\u73b0\u6570\u5b57\u5728\u540e\u53f0\u8fd8\u4f1a\u4e00\u76f4\u6253\u5370\u6570\u5b57\u3002\u5f00\u5173\u5173\u95ed\uff0c\u7a0b\u5e8f\u8fdb\u5165\u540e\u53f0\u5373\u6302\u8d77\uff0c\u4e0d\u4f1a\u518d\u6253\u5370\u6570\u5b57\u3002<\/p>\n\n\n\n<p>\uff08\u8fd9\u4e2a\u9700\u8981\u4f7f\u7528\u771f\u673a\u6d4b\u8bd5\uff0c\u6a21\u62df\u5668\u6bd4\u8f83\u7279\u6b8a\uff0c\u4e0d\u7ba1\u4ec0\u4e48\u60c5\u51b5\u7a0b\u5e8f\u8fdb\u5165\u540e\u53f0\u90fd\u4f1a\u4e00\u76f4\u8fd0\u884c\uff09<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/07\/image-67.png\" alt=\"\" class=\"wp-image-3491\" width=\"548\" height=\"374\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-67.png 996w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-67-300x205.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-67-768x524.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-67-830x567.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-67-230x157.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-67-350x239.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-67-480x328.png 480w\" sizes=\"(max-width: 548px) 100vw, 548px\" \/><\/figure><\/div>\n\n\n\n<p><strong>&#8212; ViewController.swift &#8212;<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import UIKit\n \nclass ViewController: UIViewController {\n     \n    @IBOutlet weak var textView: UITextView!\n     \n    @IBOutlet weak var mySwitch: UISwitch!\n     \n    var i=0\n     \n    override func viewDidLoad() {\n        super.viewDidLoad()\n         \n        \/\/\u521b\u5efa\u5b9a\u65f6\u4efb\u52a1\n        _ = NSTimer.scheduledTimerWithTimeInterval(1,\n            target:self,selector:Selector(\"tickDown\"),\n            userInfo:nil,repeats:true)\n    }\n     \n    \/\/\u8ba1\u65f6\u5668\u6bcf\u79d2\u89e6\u53d1\u4e8b\u4ef6\n    func tickDown() {\n        textView.text! += \"\\(i++) \"\n    }\n    \n    override func didReceiveMemoryWarning() {\n        super.didReceiveMemoryWarning()\n    }\n}\n<\/pre>\n\n\n\n<p><strong>&#8212; AppDelegate.swift &#8212;<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import UIKit\n \n@UIApplicationMain\nclass AppDelegate: UIResponder, UIApplicationDelegate {\n \n    var window: UIWindow?\n     \n    \/\/\u540e\u53f0\u4efb\u52a1\n    var backgroundTask:UIBackgroundTaskIdentifier! = nil\n \n \n    func application(application: UIApplication,\n        didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {\n        return true\n    }\n \n    func applicationWillResignActive(application: UIApplication) {\n    }\n \n    func applicationDidEnterBackground(application: UIApplication) {\n        let controller:ViewController = self.window?.rootViewController as! ViewController\n        controller.textView.text! += \"\u8fdb\u5165\u540e\u53f0 \"\n         \n        \/\/\u5982\u679c\u5df2\u5b58\u5728\u540e\u53f0\u4efb\u52a1\uff0c\u5148\u5c06\u5176\u8bbe\u4e3a\u5b8c\u6210\n        if self.backgroundTask != nil {\n            application.endBackgroundTask(self.backgroundTask)\n            self.backgroundTask = UIBackgroundTaskInvalid\n        }\n         \n        \/\/\u5982\u679c\u8981\u540e\u53f0\u8fd0\u884c\n        if controller.mySwitch.on {\n            \/\/\u6ce8\u518c\u540e\u53f0\u4efb\u52a1\n            self.backgroundTask = application.beginBackgroundTaskWithExpirationHandler({\n                () -> Void in\n                \/\/\u5982\u679c\u6ca1\u6709\u8c03\u7528endBackgroundTask\uff0c\u65f6\u95f4\u8017\u5c3d\u65f6\u5e94\u7528\u7a0b\u5e8f\u5c06\u88ab\u7ec8\u6b62\n                application.endBackgroundTask(self.backgroundTask)\n                self.backgroundTask = UIBackgroundTaskInvalid\n            })\n        }\n    }\n \n    func applicationWillEnterForeground(application: UIApplication) {\n    }\n \n    func applicationDidBecomeActive(application: UIApplication) {\n    }\n \n    func applicationWillTerminate(application: UIApplication) {\n    }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1\uff0c\u7a0b\u5e8f\u7684\u6302\u8d77\u548c\u9000\u51fa \u7531\u4e8eiOS\u8bbe\u5907\u8d44\u6e90\u6709\u9650\u3002\u5f53\u7528\u6237\u70b9\u51fb\u4e86home\u952e\uff0c\u6216\u8005\u53e6\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u4e86\u3002\u90a3\u4e48\u539f\u5148\u90a3\u4e2a\u7a0b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,8],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/3489"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3489"}],"version-history":[{"count":2,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/3489\/revisions"}],"predecessor-version":[{"id":3492,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/3489\/revisions\/3492"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}