{"id":5255,"date":"2023-05-16T12:05:36","date_gmt":"2023-05-16T04:05:36","guid":{"rendered":"https:\/\/app.applebyme.cn\/cloud\/?p=5255"},"modified":"2023-05-16T12:05:36","modified_gmt":"2023-05-16T04:05:36","slug":"ios%e5%bc%80%e5%8f%91-%e6%8e%a8%e9%80%81%e6%b6%88%e6%81%af%e6%98%af%e6%80%8e%e4%b9%88%e5%ae%9e%e7%8e%b0%e7%9a%84%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/app.applebyme.cn\/cloud\/appshangjia\/5255.html","title":{"rendered":"ios\u5f00\u53d1 \u63a8\u9001\u6d88\u606f\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff1f"},"content":{"rendered":"<p>\u63a8\u9001\u662fiOS\u5f00\u53d1\u4e2d\u975e\u5e38\u91cd\u8981\u7684\u4e00\u90e8\u5206\uff0c\u5b83\u80fd\u591f\u8ba9\u5e94\u7528\u7a0b\u5e8f\u5728\u540e\u53f0\u8fd0\u884c\u65f6\u63a5\u6536\u5230\u91cd\u8981\u7684\u6d88\u606f<a href=\"https:\/\/www.yimenapp.net\/dabao-4051.html\">ipa\u6587\u4ef6\u7f16\u8bd1<\/a>\u548c\u901a\u77e5\uff0c\u8fd9\u5bf9\u4e8e\u7528\u6237\u6765\u8bf4\u975e\u5e38\u65b9\u4fbf\u548c\u5b9e\u7528\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecdiOS\u63a8\u9001\u7684\u539f\u7406\u548c\u5b9e\u73b0\u65b9\u5f0f\u3002<\/p>\n<p>\u4e00\u3001\u63a8\u9001\u7684\u539f\u7406<\/p>\n<p>iOS\u63a8\u9001\u670d\u52a1\u7684\u539f\u7406\u662f\u57fa\u4e8eApple\u7684APNs\uff08Apple Push Notification Service\uff09\u670d\u52a1\uff0cAPNs\u662f\u4e00\u79cd\u57fa\u4e8eHTTP\/2\u534f\u8bae\u7684\u63a8\u9001\u670d\u52a1\uff0c\u5b83\u4f7f\u7528\u4e86\u4e00\u79cd\u7279\u6b8a\u7684\u63a8\u9001\u534f\u8bae\u6765\u5411iOS\u8bbe\u5907\u53d1\u9001\u901a\u77e5\u3002APNs\u670d\u52a1\u7531\u82f9\u679c\u516c\u53f8\u63d0\u4f9b\uff0c\u5f00\u53d1\u8005\u9700\u8981\u901a\u8fc7Apple Developer\u7f51\u7ad9\u6765\u83b7\u53d6APNs\u8bc1\u4e66\u548c\u5bc6\u94a5\uff0c\u4ee5\u4fbf\u5c06\u5e94\u7528\u7a0b\u5e8f\u6ce8\u518c\u5230APNs\u670d\u52a1\u4e0a\u3002<\/p>\n<p>\u5f53\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u63a5\u6536\u63a8\u9001\u6d88\u606f\u65f6\uff0c\u5b83\u9996\u5148\u8981\u5411APNs\u670d\u52a1\u5668\u6ce8\u518c\u81ea\u5df1\u7684\u8bbe\u5907\u4ee4\u724c\uff08Device Token\uff09\u3002\u8bbe<a href=\"https:\/\/www.yimenapp.net\/dabao-1338.html\">app \u5f00\u53d1\u5e73\u53f0<\/a>\u5907\u4ee4\u724c\u662f\u7531\u82f9\u679c\u670d\u52a1\u5668\u751f\u6210\u7684\uff0c\u5b83\u662f\u4e00\u4e2a\u552f\u4e00\u7684\u6807\u8bc6\u7b26\uff0c\u7528\u4e8e\u6807\u8bc6iOS\u8bbe\u5907\u3002\u5f00\u53d1\u8005\u9700\u8981\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5b9e\u73b0APNs\u6ce8\u518c\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u4f1a\u5411APNs\u670d\u52a1\u5668\u53d1\u9001\u4e00\u4e2a\u6ce8\u518c\u8bf7\u6c42\uff0c\u8bf7\u6c42\u4e2d\u5305\u542b\u5e94\u7528\u7a0b\u5e8f\u7684Bundle ID\u548c\u8bbe\u5907\u7684Token\u3002<\/p>\n<p>\u5f53APNs\u670d\u52a1\u5668\u63a5\u6536\u5230\u6ce8\u518c\u8bf7\u6c42\u540e\uff0c\u5b83\u4f1a\u5c06\u8bbe\u5907\u4ee4\u724c\u548c\u5e94\u7528\u7a0b\u5e8f\u7684Bundle ID\u8fdb\u884c\u7ed1\u5b9a\uff0c\u7136\u540e\u5c06\u8fd9\u4e9b\u4fe1\u606f\u4fdd\u5b58\u5230APNs\u6570\u636e\u5e93\u4e2d\u3002\u5f53\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u5411\u8bbe\u5907\u53d1\u9001\u63a8<\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.cdn.yimenapp.com\/2023-04\/03\/17\/19666001975.jpg\" \/><\/figure>\n<\/p>\n<p>\u9001\u6d88\u606f\u65f6\uff0c\u5b83\u9700\u8981\u5148\u5c06\u6d88\u606f\u53d1\u9001\u7ed9APNs\u670d\u52a1\u5668\uff0c\u7136\u540eAPNs\u670d\u52a1\u5668\u4f1a\u5c06\u6d88\u606f\u8f6c\u53d1\u7ed9\u76f8\u5e94\u7684\u8bbe\u5907\u3002<\/p>\n<p>\u4e8c\u3001\u63a8\u9001\u7684\u5b9e\u73b0\u65b9\u5f0f<\/p>\n<p>iOS\u5f00\u53d1\u8005\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4e24\u79cd\u65b9\u5f0f\u6765\u5b9e\u73b0\u63a8\u9001\u529f\u80fd\uff1a<\/p>\n<p>1. \u8fdc\u7a0b\u63a8\u9001\u901a\u77e5<\/p>\n<p>\u8fdc\u7a0b\u63a8\u9001\u901a\u77e5\u662f\u6307\u901a\u8fc7APNs\u670d\u52a1\u5668\u5411\u8bbe\u5907\u53d1\u9001\u63a8\u9001\u6d88\u606f\u3002\u5f00\u53d1\u8005\u9700\u8981\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5b9e\u73b0APNs\u6ce8\u518c\u65b9\u6cd5\uff0c\u5e76\u5c06\u8bbe\u5907\u4ee4\u724c\u53d1\u9001\u7ed9APNs\u670d\u52a1\u5668\u3002\u5f53\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u5411\u8bbe\u5907\u53d1\u9001\u63a8\u9001\u6d88\u606f\u65f6\uff0c\u5b83\u9700\u8981\u5148\u5c06\u6d88\u606f\u53d1\u9001\u7ed9APNs\u670d\u52a1\u5668\uff0c\u7136\u540eAPNs\u670d\u52a1\u5668\u4f1a\u5c06\u6d88\u606f\u8f6c\u53d1\u7ed9\u76f8\u5e94\u7684\u8bbe\u5907\u3002<\/p>\n<p>\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5b9e\u73b0APNs\u6ce8\u518c\u65b9\u6cd5\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<p>1\uff09\u5728AppDelegate.m\u6587\u4ef6\u4e2d\u5bfc\u5165\u5934\u6587\u4ef6#import <\/p>\n<p><p>2\uff09\u5728didFinishLaunchingWithOptions\u65b9\u6cd5\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<p>\/\/ \u6ce8\u518cAPNs\u63a8\u9001<\/p>\n<p>if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerForRemoteNotifications)]) {<\/p>\n<p>    [[UIApplication sharedApplication] registerForRemoteNotifications];<\/p>\n<p>} else {<\/p>\n<p>    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound)];<\/p>\n<p>}<\/p>\n<p>3\uff09\u5b9e\u73b0didRegisterForRemoteNotificationsWithDeviceToken\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u4f1a\u5728\u8bbe\u5907\u6ce8\u518c\u6210\u529f\u540e\u88ab\u8c03\u7528\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u5728\u8be5\u65b9\u6cd5\u4e2d\u83b7\u53d6\u8bbe\u5907\u4ee4\u724c\uff0c\u7136\u540e\u5c06\u5176\u53d1\u9001\u7ed9\u5e94\u7528\u670d\u52a1\u5668\u3002<\/p>\n<p>&#8211; (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {<\/p>\n<p>    \/\/ \u5c06\u8bbe\u5907\u4ee4\u724c\u53d1\u9001\u7ed9\u5e94\u7528\u670d\u52a1\u5668<\/p>\n<p>}<\/p>\n<p>2. \u672c\u5730\u63a8\u9001\u901a\u77e5<\/p>\n<p>\u672c\u5730\u63a8\u9001\u901a\u77e5\u662f\u6307\u5e94\u7528\u7a0b\u5e8f\u5728\u8bbe\u5907\u7aef\u751f\u6210\u4e00\u6761\u672c\u5730\u901a\u77e5\uff0c\u5f53\u5e94\u7528\u7a0b\u5e8f\u5904\u4e8e\u540e\u53f0\u6216\u8005\u8fd0\u884c\u72b6\u6001\u65f6\uff0c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u5c06\u8be5\u901a\u77e5\u663e\u793a\u5728\u8bbe\u5907\u4e0a\u3002\u5f00\u53d1\u8005\u53ef\u4ee5\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u8c03\u7528UILocalNotification\u7c7b\u6765\u5b9e\u73b0\u672c\u5730\u63a8\u9001\u901a\u77e5\u529f\u80fd\u3002<\/p>\n<p>\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5b9e\u73b0\u672c\u5730\u63a8\u9001\u901a\u77e5\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<p>1\uff09\u521b\u5efa\u4e00\u4e2aUILocalNotification\u5bf9\u8c61<\/p>\n<p>UILocalNotification *notification = [[UILocalNotification alloc] init];<\/p>\n<p>2\uff09\u8bbe\u7f6e\u901a\u77e5\u7684\u76f8\u5173\u5c5e\u6027\uff0c\u4f8b\u5982\u901a\u77e5\u5185\u5bb9\u3001\u89e6\u53d1\u65f6\u95f4\u3001\u58f0\u97f3\u7b49<\/p>\n<p>notification.alertTitle = @&#8221;\u901a\u77e5\u6807\u9898&#8221;;<\/p>\n<p>notification.alertBody = @&#8221;\u901a\u77e5\u5185\u5bb9&#8221;;<\/p>\n<p>notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];<\/p>\n<p>notification.soundName = UILocalNotificationDefaultSoundName;<\/p>\n<p>3\uff09\u8c03\u7528UIApplication\u7c7b\u7684scheduleLocalNotification\u65b9\u6cd5\u5c06\u901a\u77e5\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684\u901a\u77e5\u961f\u5217\u4e2d<\/p>\n<p>[[UIApplication sharedApplication] scheduleLocalNotification:notification];<\/p>\n<p>\u4e09\u3001\u603b\u7ed3<\/p>\n<p>\u63a8\u9001\u662fiOS\u5f00\u53d1\u4e2d\u975e\u5e38\u91cd\u8981\u7684\u4e00\u90e8\u5206\uff0c\u5b83\u80fd\u591f\u8ba9\u5e94\u7528\u7a0b\u5e8f\u5728\u540e\u53f0\u8fd0\u884c\u65f6\u63a5\u6536\u5230\u91cd\u8981\u7684\u6d88\u606f\u548c\u901a\u77e5\u3002iOS\u63a8\u9001\u670d\u52a1\u7684\u539f\u7406\u662f\u57fa\u4e8eApple\u7684APNs\u670d\u52a1\uff0c\u5f00\u53d1\u8005\u9700\u8981\u901a\u8fc7Apple Developer\u7f51\u7ad9\u6765\u83b7\u53d6APNs\u8bc1\u4e66\u548c\u5bc6\u94a5\uff0c\u4ee5\u4fbf\u5c06\u5e94\u7528\u7a0b\u5e8f\u6ce8\u518c\u5230APNs\u670d\u52a1\u4e0a\u3002iOS\u5f00\u53d1\u8005\u53ef\u4ee5\u4f7f\u7528\u8fdc\u7a0b\u63a8\u9001\u901a\u77e5\u548c\u672c\u5730\u63a8\u9001\u901a\u77e5\u4e24\u79cd\u65b9\u5f0f\u6765\u5b9e\u73b0\u63a8\u9001\u529f\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a8\u9001\u662fiOS\u5f00\u53d1\u4e2d\u975e\u5e38\u91cd\u8981\u7684\u4e00\u90e8\u5206\uff0c\u5b83\u80fd\u591f\u8ba9\u5e94\u7528\u7a0b\u5e8f\u5728\u540e\u53f0\u8fd0\u884c\u65f6\u63a5\u6536\u5230\u91cd\u8981\u7684\u6d88\u606f\u548c\u901a\u77e5\uff0c\u8fd9\u5bf9\u4e8e\u7528\u6237\u6765\u8bf4\u975e\u5e38\u65b9\u4fbf\u548c\u5b9e\u7528\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecdiOS\u63a8\u9001\u7684\u539f\u7406\u548c\u5b9e\u73b0\u65b9\u5f0f\u3002\u4e00\u3001\u63a8\u9001\u7684\u539f\u7406iOS\u63a8\u9001\u670d\u52a1<\/p>\n","protected":false},"author":15,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[7409,7408,1775,882,922],"class_list":["post-5255","post","type-post","status-publish","format-standard","hentry","category-appshangjia","tag-androidapk","tag-app","tag-1775","tag-882","tag-922"],"_links":{"self":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts\/5255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/comments?post=5255"}],"version-history":[{"count":0,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts\/5255\/revisions"}],"wp:attachment":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/media?parent=5255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/categories?post=5255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/tags?post=5255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}