{"id":19507,"date":"2024-03-15T16:58:38","date_gmt":"2024-03-15T08:58:38","guid":{"rendered":"https:\/\/www.zhidianwl.net\/zhidianwl\/?p=19507"},"modified":"2024-03-15T16:58:38","modified_gmt":"2024-03-15T08:58:38","slug":"%e7%bd%91%e9%a1%b5%e5%b0%81%e8%a3%85%e4%b8%baapp-%e8%8b%b9%e6%9e%9cios%e7%89%88%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.net\/zhidianwl\/2024\/03\/15\/%e7%bd%91%e9%a1%b5%e5%b0%81%e8%a3%85%e4%b8%baapp-%e8%8b%b9%e6%9e%9cios%e7%89%88%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0\/","title":{"rendered":"\u7f51\u9875\u5c01\u88c5\u4e3aapp \u82f9\u679cios\u7248\u5982\u4f55\u5b9e\u73b0?"},"content":{"rendered":"
\u5c06\u7f51\u9875\u5c01\u88c5\u4e3aApp\u662f\u4e00\u79cd\u5c06Web\u6280\u672f\u5e94\u7528\u4e8e\u79fb\u52a8\u5e94\u7528\u5f00\u53d1\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5c06\u4e00\u4e2a\u7f51\u7ad9\u6216\u8005Web\u5e94\u7528\u5c01\u88c5\u4e3a\u4e00\u4e2a\u72ec\u7acb\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u5e94\u7528\u5546\u5e97\u7684\u65b9\u5f0f\u4e0b\u8f7d\u5b89\u88c5\uff0c\u4ece\u800c\u83b7\u5f97\u66f4\u597d\u7684\u7528\u6237\u4f53\u9a8c\u548c\u66f4\u9ad8\u7684\u7528\u6237\u9ecf\u6027\u3002\u800c\u82f9\u679ciOS\u5e73\u53f0\u662f\u79fb\u52a8\u5e94\u7528\u5f00\u53d1\u4e2d\u6700\u91cd\u8981\u7684\u5e73\u53f0\u4e4b\u4e00\uff0c\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5c06\u7f51\u9875\u5c01\u88c5\u4e3aiOS\u5e94\u7528\u3002<\/p>\n
\u4e00\u3001\u5c01\u88c5\u539f\u7406<\/p>\n
\u7f51\u9875\u5c01\u88c5\u4e3aApp\u7684\u539f\u7406\u662f\u5c06\u7f51\u9875\u5185\u5bb9\u5d4c\u5165\u5230\u4e00\u4e2a\u539f\u751f\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u901a\u8fc7WebView\u63a7\u4ef6\u6765\u5c55\u793a\u7f51\u9875\u5185\u5bb9\uff0c\u540c\u65f6\u5229\u7528\u539f\u751f\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u7684API\u6765\u5b9e\u73b0\u4e00\u4e9b\u529f\u80fd\uff0c\u4f8b\u5982\u63a8\u9001\u901a\u77e5\u3001\u672c\u5730\u5b58\u50a8\u7b49\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5c01\u88c5\u6d41\u7a0b\uff1a<\/p>\n
1. \u521b\u5efa\u4e00\u4e2a\u7a7a\u767d\u7684iOS\u5e94\u7528\u9879\u76ee\uff1b<\/p>\n
2. \u5728\u9879\u76ee\u4e2d\u6dfb\u52a0\u4e00\u4e2aWebView\u63a7\u4ef6\uff0c\u7528\u4e8e\u5c55\u793a\u7f51\u9875\u5185\u5bb9\uff1b<\/p>\n
3. \u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u8bbe\u7f6e\u4e00\u4e9b\u5fc5\u8981\u7684\u53c2\u6570\uff0c\u4f8b\u5982\u5e94\u7528\u56fe\u6807\u3001\u5e94\u7528\u540d\u79f0\u7b49\uff1b<\/p>\n
4. \u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u6dfb\u52a0\u4e00\u4e9b\u539f\u751f\u529f\u80fd\uff0c\u4f8b\u5982\u63a8\u9001\u901a\u77e5\u3001\u672c\u5730\u5b58\u50a8\u7b49\uff1b<\/p>\n
5. \u6253\u5305\u5e94\u7528\u7a0b\u5e8f\u5e76\u4e0a\u4f20\u5230\u5e94\u7528\u5546\u5e97\u3002<\/p>\n
\u4e8c\u3001\u5c01\u88c5\u6b65\u9aa4<\/p>\n
\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5c06\u7f51\u9875\u5c01\u88c5\u4e3aiOS\u5e94\u7528\u3002<\/p>\n
1. \u521b\u5efa\u4e00\u4e2a\u7a7a\u767d\u7684iOS\u5e94\u7528\u9879\u76ee<\/p>\n
\u9996\u5148\uff0c\u5728Xcode\u4e2d\u521b\u5efa\u4e00\u4e2a\u7a7a\u767d\u7684iOS\u5e94\u7528\u9879\u76ee\u3002\u5728\u521b\u5efa\u8fc7\u7a0b\u4e2d\uff0c\u9700\u8981\u9009\u62e9\u5e94\u7528\u7c7b\u578b\u4e3a\u201cSingle View App\u201d\uff0c\u8fd9\u6837\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u53ea\u5305\u542b\u4e00\u4e2a\u89c6\u56fe\u63a7\u5236\u5668\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n
2. \u6dfb\u52a0WebView\u63a7\u4ef6<\/p>\n
\u5728\u9879\u76ee\u4e2d\u6dfb\u52a0\u4e00\u4e2aWebView\u63a7\u4ef6\uff0c\u7528\u4e8e\u5c55\u793a\u7f51\u9875\u5185\u5bb9\u3002\u5728\u89c6\u56fe\u63a7\u5236\u5668\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n
“`<\/p>\n
import UIKit<\/p>\n
import WebKit<\/p>\n
class ViewController: UIViewController {<\/p>\n
override func viewDidLoad() {<\/p>\n
super.viewDidLoad()<\/p>\n<\/p>\n
let webView = WKWebView(frame: view.bounds)<\/p>\n
view.addSubview(webView)<\/p>\n<\/p>\n
if let url = URL(string: “https:\/\/www.example.com”) {<\/p>\n
let request = URLRequest(url: url)<\/p>\n
webView.load(request)<\/p>\n
}<\/p>\n
}<\/p>\n
}<\/p>\n
“`<\/p>\n
\u8fd9\u6bb5\u4ee3\u7801\u521b\u5efa\u4e86\u4e00\u4e2aWKWebView\u63a7\u4ef6\u5e76\u52a0\u8f7d\u4e86\u4e00\u4e2a\u7f51\u9875\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u4ee5\u5c06URL\u5730\u5740\u6539\u4e3a\u9700\u8981\u5c01\u88c5\u7684\u7f51\u9875\u5730\u5740\u3002<\/p>\n
3. \u8bbe\u7f6e\u5e94\u7528\u7a0b\u5e8f\u53c2<\/p>\n
\u6570<\/p>\n \u5728\u9879\u76ee\u4e2d\u8bbe\u7f6e\u4e00\u4e9b\u5fc5\u8981\u7684\u53c2\u6570\uff0c\u4f8b\u5982\u5e94\u7528\u56fe\u6807\u3001\u5e94\u7528\u540d\u79f0\u7b49\u3002\u5728Xcode\u4e2d\uff0c\u53ef\u4ee5\u5728\u201cGeneral\u201d\u9009\u9879\u5361\u4e2d\u8bbe\u7f6e\u8fd9\u4e9b\u53c2\u6570\u3002<\/p>\n 4. \u6dfb\u52a0\u539f\u751f\u529f\u80fd<\/p>\n \u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u6dfb\u52a0\u4e00\u4e9b\u539f\u751f\u529f\u80fd\uff0c\u4f8b\u5982\u63a8\u9001\u901a\u77e5\u3001\u672c\u5730\u5b58\u50a8\u7b49\u3002\u8fd9\u4e9b\u529f\u80fd\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528\u7cfb\u7edfAPI\u6765\u5b9e\u73b0\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u6dfb\u52a0\u63a8\u9001\u901a\u77e5\u529f\u80fd\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n “`<\/p>\n import UIKit<\/p>\n import UserNotifications<\/p>\n @UIApplicationMain<\/p>\n class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {<\/p>\n func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {<\/p>\n<\/p>\n UNUserNotificationCenter.current().delegate = self<\/p>\n<\/p>\n UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in<\/p>\n if granted {<\/p>\n DispatchQueue.main.async {<\/p>\n application.registerForRemoteNotifications()<\/p>\n }<\/p>\n }<\/p>\n }<\/p>\n<\/p>\n return true<\/p>\n }<\/p>\n<\/p>\n func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {<\/p>\n \/\/ \u6ce8\u518c\u6210\u529f\uff0c\u5c06deviceToken\u53d1\u9001\u5230\u670d\u52a1\u5668<\/p>\n }<\/p>\n<\/p>\n func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Eandroid\u539f\u751f\u5f00\u53d1\u548c\u6df7\u5408\u5f00\u53d1\u4f18\u7f3a\u70b9<\/a>rror) {<\/p>\n \/\/ \u6ce8\u518c\u5931\u8d25\uff0c\u5904\u7406\u9519\u8bef<\/p>\n }<\/p>\n<\/p>\n func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {<\/p>\n completionHandler([.alert, .sound])<\/p>\n }<\/p>\n }<\/p>\n “`<\/p>\n \u8fd9\u6bb5\u4ee3\u7801\u5b9e\u73b0\u4e86\u63a8\u9001\u901a\u77e5\u7684\u6ce8\u518c\u548c\u5904\u7406\u529f\u80fd\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u6dfb\u52a0\u5176\u4ed6\u539f\u751f\u529f\u80fd\u3002<\/p>\n 5. \u6253\u5305\u5e94\u7528\u7a0b\u5e8f\u5e76\u4e0a\u4f20\u5230\u5e94\u7528\u5546\u5e97<\/p>\n<\/figure>\n<\/p>\n