{"id":69,"date":"2024-06-02T23:13:59","date_gmt":"2024-06-02T15:13:59","guid":{"rendered":"https:\/\/hexiaoyang.top\/?p=69"},"modified":"2024-07-03T08:33:21","modified_gmt":"2024-07-03T00:33:21","slug":"69","status":"publish","type":"post","link":"https:\/\/hexiaoyang.top\/index.php\/2024\/06\/02\/69\/","title":{"rendered":"push\u4eff\u5fae\u4fe1\u8bed\u97f3\u6765\u7535"},"content":{"rendered":"<h1>0 \u63a8\u9001\u7684\u5206\u7c7b<\/h1>\n<p>\u5728\u4ecb\u7ecd\u65b9\u6848\u4e4b\u524d\uff0c\u5148\u7b80\u5355\u8fc7\u4e00\u4e0bpush\u7684\u7c7b\u578b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/\u63a8\u9001\u5206\u7c7b.png\" alt=\"\" \/><\/p>\n<p>\u53c2\u8003\uff1a<a href=\"https:\/\/developer.apple.com\/documentation\/usernotifications\/sending-notification-requests-to-apns?language=objc\">sending-notification-requests-to-apns?language=objc<\/a><\/p>\n<p>\u8fdc\u7a0b\u63a8\u9001\u7684\u5206\u7c7b\u5f88\u591a\uff0c\u8bbe\u5907\u63a5\u53d7\u5230\u4e00\u6761\u63a8\u9001\u6d88\u606f\u540e\uff0c\u5982\u4f55\u5206\u53d1\uff0c\u53d6\u51b3\u4e8e\u6d88\u606f\u5934\uff0c\u4ee5\u53capayload\u7684\u5185\u5bb9\u3002\u5728\u8fd9\u4e9b\u5f53\u4e2d\uff0c\u7b26\u5408\u6211\u4eec\u901a\u8fc7push\u6a21\u62df\u6765\u7535\u7684\uff0c\u4ec5\u6709voip\uff08\u91c7\u7528PushKit+CallKit\uff0c\u53c2\u8003\u5982\u6d41\uff09\uff0c\u4ee5\u53caalert\uff08\u53c2\u8003\u5fae\u4fe1\uff09\uff0c\u800c\u7531\u4e8e\u653f\u7b56\u539f\u56e0\uff0c\u6211\u4eec\u53ea\u80fd\u9009\u53d6\u540e\u8005\u3002<\/p>\n<p>\u4e00\u4e9b\u53c2\u8003\u6587\u732e<\/p>\n<ul>\n<li>\n<p>push to talk:<br \/>\n<a href=\"https:\/\/developer.apple.com\/documentation\/pushtotalk?language=objc\">https:\/\/developer.apple.com\/documentation\/pushtotalk?language=objc<\/a><br \/>\n<a href=\"https:\/\/developer.apple.com\/documentation\/pushtotalk\/creating-a-push-to-talk-app?language=objc\">https:\/\/developer.apple.com\/documentation\/pushtotalk\/creating-a-push-to-talk-app?language=objc<\/a><\/p>\n<\/li>\n<li>\n<p>background:<br \/>\n<a href=\"https:\/\/developer.apple.com\/documentation\/usernotifications\/pushing-background-updates-to-your-app?language=objc\">https:\/\/developer.apple.com\/documentation\/usernotifications\/pushing-background-updates-to-your-app?language=objc<\/a><\/p>\n<\/li>\n<li>\n<p>fileprovider<br \/>\n<a href=\"https:\/\/developer.apple.com\/documentation\/pushkit\/pkpushtype\/fileprovider?language=objc\">https:\/\/developer.apple.com\/documentation\/pushkit\/pkpushtype\/fileprovider?language=objc<\/a><\/p>\n<\/li>\n<li>\n<p>location<br \/>\n<a href=\"https:\/\/developer.apple.com\/documentation\/corelocation\/creating_a_location_push_service_extension?language=objc\">https:\/\/developer.apple.com\/documentation\/corelocation\/creating_a_location_push_service_extension?language=objc<\/a><\/p>\n<\/li>\n<\/ul>\n<h1>1 alert\u6d88\u606f\u5904\u7406\u6d41\u7a0b\u56de\u987e<\/h1>\n<p>\u9274\u4e8eVoip(PushKit + CallKit)\u65b9\u6848\u5ba1\u6838\u88ab\u62d2\uff0c\u73b0\u8bbe\u8ba1\u5fae\u4fe1\u7684\u8bed\u97f3\u6765\u7535\u65b9\u6848\u3002\u7ecf\u8fc7\u8c03\u7528\uff0c\u8fdc\u7a0b\u63a8\u9001\u4e2d\u7684alert\u6a21\u5f0f\u7684\u63a8\u9001\uff0c\u7b26\u5408\u6211\u4eec\u7684\u573a\u666f(\u5176\u4ed6\u6a21\u5f0f\u53c2\u8003\uff1a)\uff0c\u5728\u65b9\u6848\u8bbe\u8ba1\u524d\uff0c\u5148\u56de\u987e\u4e00\u4e0b\u4e00\u6761alert\u63a8\u9001\u6d88\u606f\u7684\u6d41\u8f6c\u8fc7\u7a0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/570402910635488.png\" alt=\"\" \/><br \/>\n\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u6709\u4e09\u70b9\u9700\u8981\u6ce8\u610f\uff1a<\/p>\n<ol>\n<li>\u6bcf\u6761push\u6700\u5927\u7684\u5904\u7406\u65f6\u95f4\u7ea6\u4e3a30s<\/li>\n<li>\u82e5\u4e3b\u52a8\u8c03\u7528Complete\u63a8\u51fa\u6a2a\u5e45\u540e\uff0c\u6700\u591a\u8fd8\u67095s\u7684\u65f6\u95f4\u5904\u7406\u5176\u4ed6\u4e8b\u7269<\/li>\n<li>\u8d85\u8fc730s\u540e\uff0c\u4f1a\u89e6\u53d1\u7cfb\u7edf\u51fd\u6570<code>-serviceExtensionTimeWillExpire<\/code>\uff0c\u8be5\u51fd\u6570\u4f1a\u9690\u5f0f\u8c03\u7528Complete\uff0c\u63a8\u51fa\u6a2a\u5e45\u3002<\/li>\n<\/ol>\n<h1>2 \u8bbe\u8ba1\u76ee\u6807\u53ca\u65b9\u6848<\/h1>\n<p>\u6211\u4eec\u7684\u8bbe\u8ba1\u76ee\u6807\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>APP\u6536\u5230\u3010\u8bed\u97f3\u7535\u8bdd\u7c7b\u578b\u3011\u7684\u63a8\u9001\u6d88\u606f\u540e\uff0c\u8bbe\u5907\u9876\u90e8\u5c55\u793a\u6a2a\u5e45\uff0c\u5e76\u6301\u7eed\u9707\u52a8&amp;\u54cd\u94c3(\u82e5\u5f00\u4e86\u9759\u97f3\u5219\u65e0\u6cd5\u54cd\u94c3)<\/li>\n<li>\u9707\u52a8&amp;\u54cd\u94c3\u671f\u95f4\uff0c\u9501\u5c4f&amp;\u901a\u77e5\u4e2d\u5fc3\u663e\u793a\u6765\u7535\u6d88\u606f<\/li>\n<li>APP\u8fdb\u524d\u53f0\uff0c\u505c\u6b62\u9707\u52a8&amp;\u54cd\u94c3\uff0c\u5524\u8d77\u7aef\u5185\u6765\u7535\u5f39\u7a97\u3002\u5e76\u79fb\u9664\u9501\u5c4f&amp;\u901a\u77e5\u4e2d\u5fc3\u7684\u901a\u77e5<\/li>\n<li>\u8d85\u65f6\u672a\u63a5\u542c\uff0c\u505c\u6b62\u9707\u52a8&amp;\u54cd\u94c3\uff0c\u5e76\u79fb\u9664\u9501\u5c4f&amp;\u901a\u77e5\u4e2d\u5fc3\u7684\u901a\u77e5(\u53ef\u9009)<\/li>\n<li>\u63a8\u9001\u671f\u95f4\uff0c\u670d\u52a1\u7aef\u7ec8\u6b62\u547c\u53eb\uff0c\u8bbe\u5907\u505c\u6b62\u9707\u52a8&amp;\u54cd\u94c3\uff0c\u5e76\u79fb\u9664\u9501\u5c4f&amp;\u901a\u77e5\u4e2d\u5fc3\u7684\u901a\u77e5(\u53ef\u9009)<\/li>\n<\/ol>\n<p>\u4e0b\u9762\u9488\u5bf9\u76ee\u6807\uff0c\u5206\u522b\u8fdb\u884c\u65b9\u6848\u8bbe\u8ba1\uff1a<\/p>\n<h3>\u76ee\u68071\uff1a\u6536\u5230\u63a8\u9001\u540e\uff0c\u6301\u7eed\u9707\u52a8\u3001\u54cd\u94c3<\/h3>\n<p>\u9996\u5148\uff0c\u540e\u7aef\u63a8\u7684push\u6d88\u606f\u7ed3\u6784\u4e2d\uff0c\u4e00\u5b9a\u8981\u6709\u4e00\u4e2a\u5b57\u6bb5\uff0c\u7528\u4e8e\u6807\u8bc6\u6765\u7535\uff0c\u7ed3\u5408\u76ee\u68075\uff0c\u6211\u4eec\u53ef\u4ee5\u8bbe\u8ba1\u7ed3\u6784\u5982\u4e0b\uff08alert\u7c7b\u578b\u652f\u6301\u7684\u5b8c\u6574\u53c2\u6570\uff1a<a href=\"https:\/\/developer.apple.com\/documentation\/usernotifications\/generating-a-remote-notification?language=objc\">https:\/\/developer.apple.com\/documentation\/usernotifications\/generating-a-remote-notification?language=objc<\/a>\uff09\uff1a<\/p>\n<pre><code class=\"language-json\">{\n    &quot;pushType&quot;: 1, \/\/ 1\u4e3a\u6765\u7535 2\u4e3a\u6302\u65ad\n    &quot;aps&quot;:\n    {\n        &quot;alert&quot;:\n        {\n            &quot;title&quot;: &quot;\u63a8\u9001\u901a\u77e5\u6807\u9898&quot;, \n            &quot;subtitle&quot;: &quot;\u63a8\u9001\u901a\u77e5\u526f\u6807\u9898&quot;,\n            &quot;body&quot;: &quot;\u8fd9\u662f\u63a8\u9001\u901a\u77e5\u7684\u6b63\u6587\u5185\u5bb9&quot;\/\/\u6700\u591a4\u884c\u5b57\n        },\n        &quot;mutable-content&quot;: 1 \/\/\u8fd9\u91cc\u5fc5\u987b\u8bbe\u7f6e\u4e3a1\n    }\n}<\/code><\/pre>\n<p>\u9759\u6001\u6548\u679c\u5982\u56fe\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/313362734961239.png\" alt=\"\" \/><img decoding=\"async\" src=\"http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/443852898909643.png\" alt=\"\" \/><\/p>\n<p>\u5f53\u6536\u5230\u63a8\u9001\u540e\uff0c\u82e5pushType\u4e3a1\u65f6\uff0c\u5c31\u662f\u6211\u4eec\u5904\u7406\u6765\u7535\u8bed\u97f3\u7684\u65f6\u673a\u3002\u7531\u4e8e\u6d88\u606f\u4f53\u4e2dmutabe-content\u5b57\u6bb5\u7684\u8bbe\u7f6e\uff0c\u4f7f\u5f97Push Service\u63d2\u4ef6\u80fd\u591f\u6536\u5230\u6d88\u606f\u8fdb\u884c\u5904\u7406\uff0c\u5373\u6267\u884c\u4e86<code>-didReceiveNotificationRequest:withContentHandler:<\/code>\u65b9\u6cd5<\/p>\n<p>\u5728\u8fd9\u4e2a\u65b9\u6cd5\u4e2d\u6211\u4eec\u53ef\u4ee5\u63a8\u51fa\u6a2a\u5e45\uff0c\u7136\u540e\u5728\u65b0\u7ebf\u7a0b\u5faa\u73af\u64ad\u653e\u9707\u52a8&amp;\u94c3\u58f0\uff0c\u540c\u65f6\u6302\u8d77\u5f53\u524d\u7ebf\u7a0b\uff0c\u9632\u6b62\u7531\u4e8e\u6a2a\u5e45\u88ab\u63a8\u51fa\u540e\uff0c\u6574\u4e2a\u6d41\u7a0b\u53ea\u80fd\u6267\u884c5s\uff1a<\/p>\n<pre><code>- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {\n    self.contentHandler = contentHandler;\n    self.bestAttemptContent = [request.content mutableCopy];\n\n    NSDictionary *pushDictionary = request.content.userInfo;\n    __weak typeof(self) weakSelf = self;\n    if ([pushDictionary.allKeys containsObject:@&quot;pushType&quot;]) {\n        [[DXMPushPhoneManager shareManager] callingWithRequest:request complete:^(UNNotificationContent * _Nonnull contentToDeliver) {        \n            weakSelf.contentHandler(contentToDeliver);\n        }];\n    }\n}<\/code><\/pre>\n<p>\u8fd9\u91cc\u6211\u4eec\u770b\u4e0b\u5728Push Service\u8fdb\u7a0b\u4e2d\u7684\u9ed8\u8ba4\u7ebf\u7a0b endpoint\uff1a<br \/>\n<img decoding=\"async\" src=\"http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/126474226142763.png\" alt=\"\" \/><\/p>\n<p>\u800c\u6211\u4eec\u7684\u9707\u52a8&amp;\u54cd\u94c3\u4efb\u52a1\u6267\u884c\u5728\u4e3b\u7ebf\u7a0b\uff1a<br \/>\n<img decoding=\"async\" src=\"http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/119844174957107.png\" alt=\"\" \/><\/p>\n<p>\u53ef\u4ee5\u786e\u8ba4\u6302\u8d77endpoint\u7ebf\u7a0b\uff0c\u4e0d\u4f1a\u5f71\u54cd\u9707\u52a8&amp;\u54cd\u94c3\u7684\u4efb\u52a1<\/p>\n<p>\u7136\u540e\u6211\u4eec\u8fd8\u8981\u505a\u4e00\u4e9b\u8f85\u52a9\u6027\u7684\u4e8b\u52a1\uff1a<\/p>\n<ul>\n<li>\u5728\u6c99\u76d2\u4e2d\u5b58\u50a8\u6765\u7535push\u7684\u6d88\u606f\u3002\uff08\u6ce8\u610f\u4f7f\u7528appgroup\u8de8\u8fdb\u7a0b\u6c99\u76d2\u5b58\u50a8\uff09<\/li>\n<\/ul>\n<h3>\u76ee\u68072 \u9707\u52a8&amp;\u54cd\u94c3\u671f\u95f4\uff0c\u9501\u5c4f&amp;\u901a\u77e5\u4e2d\u5fc3\u663e\u793a\u6765\u7535\u6d88\u606f<\/h3>\n<p>\u7531\u4e8e\u5728\u4e0a\u4e00\u6b65\u4e2d\uff0c\u5728\u542f\u52a8\u9707\u52a8&amp;\u94c3\u58f0\u5faa\u73af\u4efb\u52a1\u540e\uff0c\u5c31\u4e3b\u52a8\u63a8\u51fa\u4e86\u6a2a\u5e45\uff0c\u6545\u672c\u76ee\u6807\u53ef\u4ee5\u6ee1\u8db3<\/p>\n<h3>\u76ee\u68073 APP\u542f\u52a8\/\u56de\u5230\u524d\u53f0\u7684\u5904\u7406<\/h3>\n<p>1.\u505c\u6389\u9707\u52a8&amp;\u54cd\u94c3\uff1a \u5f53APP\u8fdb\u5165\u524d\u53f0\u540e\uff0c\u6c99\u76d2\u66f4\u65b0\u5bf9\u5e94\u6807\u8bb0\u4f4d\uff08\u6ce8\u610f\u4f7f\u7528appgroup\u8de8\u8fdb\u7a0b\u6c99\u76d2\u5b58\u50a8\uff09\uff0cPush Service\u8fdb\u7a0b\u4e2d\uff0c\u9707\u52a8&amp;\u94c3\u58f0\u5b9a\u65f6\u5668\u6bcf\u6b21\u5faa\u73af\u90fd\u6839\u636e\u6807\u8bb0\u4f4d\uff08\u6ce8\u610f\u4f7f\u7528appgroup\u8de8\u8fdb\u7a0b\u8bfb\u53d6\u6c99\u76d2\uff09\uff0c\u5224\u65ad\u662f\u5426\u505c\u6b62\u5faa\u73af\u3002\u56e0\u6b64\u672c\u76ee\u6807\u8fbe\u6210\u3002<\/p>\n<ol start=\"2\">\n<li>\u5728\u76ee\u68071\u7684\u65b9\u6848\u4e2d\uff0c\u6211\u4eec\u5728\u6c99\u76d2\u4e2d\u5b58\u50a8\u4e86push\u7684\u6d88\u606f\uff0c\u90a3\u4e48\u65e0\u8bba\u662f\u7528\u6237\u70b9\u51fb\u684c\u9762\u56fe\u6807\uff0c\u8fd8\u662f\u70b9\u51fbPush\u5c06APP\u62c9\u8d77\uff0c\u6211\u4eec\u90fd\u53ea\u9700\u8981\u4ece\u6c99\u76d2\u4e2d\u8bfb\u53d6push\u7684\u6570\u636e\u5373\u53ef\uff08\u4e3a\u7edf\u4e00\u5904\u7406\uff0c\u653e\u5f03\u6389\u5bf9scheme\u62c9\u8d77\u7684\u5904\u7406\uff09<\/li>\n<\/ol>\n<h3>\u76ee\u68074 \u8d85\u65f6\u5904\u7406<\/h3>\n<p>\u7528\u6237\u8d85\u65f6\u672a\u70b9\u51fb\u63a8\u9001\u6761\uff0c\u6216\u4e3b\u52a8\u6253\u5f00APP\uff0c\u5bfc\u81f4\u89e6\u53d1<code>-serviceExtensionTimeWillExpire<\/code>\u51fd\u6570\uff0c\u90a3\u4e48\u5728\u8fd9\u4e2a\u65f6\u673a\uff1a<\/p>\n<ol>\n<li>\u8d77\u4e00\u6761\u672c\u5730push\uff0c\u63d0\u793a\u7528\u6237\u672a\u63a5\u542c\uff08\u53ef\u9009\uff09<\/li>\n<li>\u8c03\u7528  <code>[[UNUserNotificationCenter currentNotificationCenter] removeDeliveredNotificationsWithIdentifiers:identifers];<\/code> \u6e05\u695a\u6389\u901a\u77e5\u680f\u4e2d\u7684\u901a\u77e5\uff08\u53ef\u9009\uff09<\/li>\n<li>\u6e05\u695a\u6c99\u76d2\u4e2d\u7684push\u4fe1\u606f<\/li>\n<\/ol>\n<h3>\u76ee\u68075 \u4e2d\u65ad\u547c\u53eb\u5904\u7406<\/h3>\n<p>\u540e\u7aef\u4e0b\u53d1\u4e00\u6761 pushType\u4e3a2\u7684push\u6d88\u606f\uff0c\u7aef\u4e0a\u5728\u5904\u7406\u65f6\uff1a<\/p>\n<ol>\n<li>\u505c\u6389\u9707\u52a8&amp;\u94c3\u58f0\u5faa\u73af\u4efb\u52a1<\/li>\n<li>\u8c03\u7528  <code>[[UNUserNotificationCenter currentNotificationCenter] removeDeliveredNotificationsWithIdentifiers:identifers];<\/code> \u6e05\u9664\u6389\u901a\u77e5\u680f\u4e2d\u7684\u901a\u77e5<\/li>\n<li>\u79fb\u9664\u6c99\u76d2\u4e2d\u7684push\u6d88\u606f<\/li>\n<li>\u63a8\u51fa\u6302\u65ad\u63a8\u9001\u6a2a\u5e45\uff0c\u64ad\u653e\u6302\u65ad\u97f3\u6548\uff0c\u6e05\u9664\u6389\u901a\u77e5\u680f\u4e2d\u7684\u901a\u77e5\uff08\u53ef\u9009\uff09<\/li>\n<\/ol>\n<h3>\u5b8c\u6574\u7684Demo\u6548\u679c<\/h3>\n<ol>\n<li>\n<p>\u672a\u63a5\u542c <div style=\"width: 540px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-69-1\" width=\"540\" height=\"960\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/\u8d85\u65f6\u672a\u63a5\u542c.mp4?_=1\" \/><a href=\"http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/\u8d85\u65f6\u672a\u63a5\u542c.mp4\">http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/\u8d85\u65f6\u672a\u63a5\u542c.mp4<\/a><\/video><\/div><\/p>\n<\/li>\n<li>\n<p>\u63a5\u542c <div style=\"width: 740px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-69-2\" width=\"740\" height=\"1316\" poster=\"http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/\u7528\u6237\u63a5\u542c-mp4-image.jpg\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/\u7528\u6237\u63a5\u542c.mp4?_=2\" \/><a href=\"http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/\u7528\u6237\u63a5\u542c.mp4\">http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/\u7528\u6237\u63a5\u542c.mp4<\/a><\/video><\/div><\/p>\n<\/li>\n<\/ol>\n<p>3.\u7ec8\u6b62\u547c\u53eb <div style=\"width: 540px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-69-3\" width=\"540\" height=\"960\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/\u7ec8\u6b62\u547c\u53eb.mp4?_=3\" \/><a href=\"http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/\u7ec8\u6b62\u547c\u53eb.mp4\">http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/\u7ec8\u6b62\u547c\u53eb.mp4<\/a><\/video><\/div><\/p>\n<h1>3 \u8fd8\u80fd\u505a\u54ea\u4e9b\u4e8b\u60c5\uff1f<\/h1>\n<h2>3.1 \u5b9a\u5236\u5316Push\u901a\u77e5\u5b8c\u6574\u9875\u9762(iOS10+)<\/h2>\n<p>\u5f53\u7528\u6237\u957f\u6309push\u6761\u65f6\uff0c\u82f9\u679c\u63d0\u4f9b\u4e86\u5c55\u793a\u4e00\u4e2a\u5b8c\u6574push\u5185\u5bb9\u9875\u9762\u7684\u80fd\u529b\uff08\u4e0d\u9700\u8981\u542f\u52a8app\uff09,  <\/p>\n<p>\u8fd9\u4e2a\u9700\u8981\u6211\u4eec\u5f15\u5165 Notification Content Extension\u7684\u80fd\u529b\uff1a<\/p>\n<p>\u6b65\u9aa4 1\uff1a\u521b\u5efa\u901a\u77e5\u5185\u5bb9\u6269\u5c55\u76ee\u6807<\/p>\n<p>\u5728 Xcode \u4e2d\uff0c\u9009\u62e9\u4f60\u7684\u9879\u76ee\u6587\u4ef6\u3002<br \/>\n\u70b9\u51fb\u5de6\u4e0b\u89d2\u7684\u52a0\u53f7\u6309\u94ae\uff0c\u9009\u62e9 \u201cNew Target\u201d\u3002<br \/>\n\u5728\u6a21\u677f\u9009\u62e9\u754c\u9762\uff0c\u9009\u62e9 \u201cNotification Content Extension\u201d\u3002<br \/>\n\u70b9\u51fb \u201cNext\u201d\uff0c\u7136\u540e\u586b\u5199\u6269\u5c55\u7684\u540d\u79f0\u548c\u5176\u4ed6\u4fe1\u606f\u3002<br \/>\n\u70b9\u51fb \u201cFinish\u201d\u3002<br \/>\nXcode \u4f1a\u4e3a\u4f60\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6269\u5c55\uff0c\u5e76\u5305\u542b\u4e00\u4e9b\u793a\u4f8b\u4ee3\u7801\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/163914217921433.png\" alt=\"\" \/><\/p>\n<p>\u6b65\u9aa4 2\uff1a\u914d\u7f6e\u6269\u5c55\u7684 Info.plist<br \/>\n\u6253\u5f00\u65b0\u521b\u5efa\u7684\u6269\u5c55\u76ee\u6807\u4e2d\u7684 Info.plist \u6587\u4ef6\u3002<br \/>\n\u786e\u4fdd NSExtension \u5b57\u5178\u4e2d\u5305\u542b\u4ee5\u4e0b\u952e\u503c\u5bf9\uff1a(UNNotificationExtensionDefaultContentHidden \u63a7\u5236\u7684\u662f\u662f\u5426\u5728\u5934\u90e8\u5c55\u793a\u63a8\u9001\u6761\u7684\u5185\u5bb9)<\/p>\n<pre><code>&lt;key&gt;NSExtension&lt;\/key&gt;\n&lt;dict&gt;\n    &lt;key&gt;NSExtensionAttributes&lt;\/key&gt;\n    &lt;dict&gt;\n        &lt;key&gt;UNNotificationExtensionCategory&lt;\/key&gt;\n        &lt;string&gt;your_category_identifier&lt;\/string&gt;\n        &lt;key&gt;UNNotificationExtensionInitialContentSizeRatio&lt;\/key&gt;\n        &lt;real&gt;0.5&lt;\/real&gt;\n        &lt;key&gt;UNNotificationExtensionDefaultContentHidden&lt;\/key&gt; \n        &lt;true\/&gt;\n    &lt;\/dict&gt;\n    &lt;key&gt;NSExtensionPointIdentifier&lt;\/key&gt;\n    &lt;string&gt;com.apple.usernotifications.content-extension&lt;\/string&gt;\n&lt;\/dict&gt;\n<\/code><\/pre>\n<p>\u6b65\u9aa4 3\uff1a\u5b9e\u73b0\u6269\u5c55\u7684\u4e3b\u754c\u9762<br \/>\n\u5728\u6269\u5c55\u76ee\u6807\u4e2d\uff0cXcode \u4f1a\u751f\u6210\u4e00\u4e2a\u5305\u542b NotificationViewController\u793a\u4f8b\u89c6\u56fe\u63a7\u5236\u5668\u3002\u8fd9\u4e2a\u89c6\u56fe\u63a7\u5236\u5668\u9700\u8981\u9075\u5faa UNNotificationContentExtension \u534f\u8bae\u3002\u6211\u968f\u4fbf\u641e\u4e86\u4e0b\u5e03\u5c40<\/p>\n<p>\u6b65\u9aa44\uff1a\u6ce8\u518c\u3002\u6ce8\u610f\u8fd9\u91cc\u7684<code>your_category_identifier<\/code>\u8981\u548cplist\u4e2d\u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n<pre><code>- (void)registerNotificationCategories {\n    UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:@&quot;your_category_identifier&quot;\n                                                                              actions:@[]\n                                                                    intentIdentifiers:@[]\n                                                                              options:UNNotificationCategoryOptionCustomDismissAction];\n    [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObject:category]];\n}\n\n- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\n    [self registerNotificationCategories];\n    return YES;\n}\n<\/code><\/pre>\n<p>\u6b65\u9aa45\uff1a\u53d1\u9001\u901a\u77e5\u3002\u8981\u6ce8\u610f\u901a\u77e5\u4e2d\u7684category\u5b57\u6bb5\u8981\u5bf9\u5e94\uff1a<\/p>\n<pre><code>{\n  &quot;aps&quot;: {\n    &quot;alert&quot;: {\n      &quot;title&quot;: &quot;\u7d27\u6025\u901a\u77e5&quot;,\n      &quot;subtitle&quot;: &quot;\u8bf7\u7acb\u5373\u67e5\u770b&quot;,\n      &quot;body&quot;: &quot;\u8fd9\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u63a8\u9001\u901a\u77e5\u5185\u5bb9\u3002&quot;,\n    },\n    &quot;sound&quot;: &quot;default&quot;,\n    &quot;badge&quot;: 1,\n    &quot;category&quot;: &quot;your_category_identifier&quot;,\n    &quot;mutable-content&quot;: 1,\n    &quot;content-available&quot;: 1\n  }\n}\n<\/code><\/pre>\n<h2>3.2 \u5b9a\u5236\u5316Push\u901a\u77e5\u5feb\u6377\u6309\u94ae<\/h2>\n<p>\u8fd9\u4e2a\u5176\u5b9e\u548c3.1\u4e00\u6837\uff0c\u4e5f\u662f\u501f\u52a9\u4e8eNotification Content Extension\u7684\u80fd\u529b\uff0c\u53ea\u9700\u8981\u5728\u6ce8\u518c\u7684\u65f6\u5019\uff0c\u52a0\u4e0a\u6309\u94ae\u5373\u53ef\uff1a<\/p>\n<pre><code>- (void)registerNotificationCategories {\n\n    \/\/ \u5b9a\u4e49\u56de\u590d\u64cd\u4f5c\n      UNTextInputNotificationAction *replyAction = [UNTextInputNotificationAction actionWithIdentifier:@&quot;REPLY_ACTION&quot;\n                                                                                                title:@&quot;\u56de\u590d&quot;\n                                                                                              options:UNNotificationActionOptionAuthenticationRequired\n                                                                                textInputButtonTitle:@&quot;Send&quot;\n                                                                                textInputPlaceholder:@&quot;Type your message&quot;];\n\n      \/\/ \u5b9a\u4e49\u67e5\u770b\u5bf9\u8bdd\u64cd\u4f5c\n      UNNotificationAction *viewAction = [UNNotificationAction actionWithIdentifier:@&quot;VIEW_ACTION&quot;\n                                                                              title:@&quot;\u67e5\u770b&quot;\n                                                                            options:UNNotificationActionOptionForeground];\n\n    UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:@&quot;hexiaoyang_category_identifier&quot;\n                                                                              actions:@[replyAction, viewAction]\n                                                                    intentIdentifiers:@[]\n                                                                              options:UNNotificationCategoryOptionCustomDismissAction];\n    [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObject:category]];\n}\n<\/code><\/pre>\n<p>\u6548\u679c\uff1a<div style=\"width: 740px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-69-4\" width=\"740\" height=\"1316\" poster=\"http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/\u6309\u538b-mp4-image.jpg\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/\u6309\u538b.mp4?_=4\" \/><a href=\"http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/\u6309\u538b.mp4\">http:\/\/hexiaoyang.top\/wp-content\/uploads\/2024\/06\/\u6309\u538b.mp4<\/a><\/video><\/div><\/p>\n<p>\u81ea\u5b9a\u4e49\u6309\u538b\u754c\u9762\u53c2\u8003 <a href=\"https:\/\/developer.apple.com\/documentation\/UserNotificationsUI\/customizing-the-appearance-of-notifications?language=objc\">customizing-the-appearance-of-notifications?language=objc<\/a><\/p>\n<h2>3.3 \u5b9a\u5236\u5316\u5de6\u4fa7logo\uff08iOS15+\uff09<\/h2>\n<p>\u8fd9\u4e2a\u9ed8\u8ba4\u662fapp\u7684icon\uff0c\u90a3\u4e48\u5982\u679c\u60f3\u6362\uff0c\u9700\u8981\u989d\u5916\u501f\u52a9 Communication Notification \u4ee5\u53ca Siri Intent\u7684\u80fd\u529b\u3002<\/p>\n<p>\u8fd9\u91cc\u6709\u7bc7\u6587\u7ae0\u5199\u7684\u5f88\u7ec6\uff0c<a href=\"https:\/\/blog.51cto.com\/u_16099298\/7448153\">7448153<\/a> \u4e0d\u8fc7\u591a\u8d58\u8ff0<\/p>\n<h2>4 Q&amp;A<\/h2>\n<p>Q: push\u901a\u77e5\u6761\u7684\u6837\u5f0f\u80fd\u591f\u5b9a\u5236\u5417\uff1f<br \/>\nA\uff1a\u4e0d\u80fd\u5b9a\u5236\uff0c\u6700\u591a\u5c55\u793a\u5de6\u4fa7logo\u3001\u4e3b\u6807\u9898\u3001\u526f\u6807\u9898\u3001\u548c\u6700\u591a4\u884c\u5185\u5bb9\u533a\u3002\u53f3\u4fa7\u53ef\u4ee5\u5c55\u793a\u9644\u4ef6\u7684\u7f29\u7565\u56fe\u3002<br \/>\n\u53e6\u5916\u53ef\u4ee5\u5b9a\u5236\u957f\u6309Push\u6761\u540e\u5c55\u793a\u7684\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u9875\u9762\uff0c\u53c2\u80033.1\u8282\u3002\u4e5f\u53ef\u4ee5\u5b9a\u5236\u957f\u6309\u540e\u7684\u5feb\u6377\u6309\u94ae\uff0c\u53c2\u80033.2\u8282<\/p>\n<p>Q: push\u672c\u8eab\u7684\u94c3\u58f0\uff0c\u4f1a\u548cpush\u6765\u7535\u51b2\u7a81\u5417\uff1f<br \/>\nA: \u5982\u679c\u901a\u77e5\u5185\u5bb9\u4e2d\u542b\u6709 mutable-content\uff1a1\u5b57\u6bb5\uff0c\u8fd9\u610f\u5473\u7740\u7aef\u4e0a\u53ef\u4ee5\u5b9a\u5236\u5316\u5904\u7406\uff0c\u4ee5\u672c\u573a\u666f\u4e3a\u4f8b\uff0c\u53ea\u9700\u8981\u5728\u63a8\u51fa\u6a2a\u5e45\u524d\uff0c\u5220\u6389\u6a2a\u5e45\u6570\u636e\u4e2d\u7684sound\u5b57\u6bb5\uff1a<\/p>\n<pre><code>\/\/\u6e05\u7a7a\u58f0\u97f3\nself.bestAttemptContent.sound = nil;\n\/\/\u63a8\u51fa\u6a2a\u5e45\nself.contentHandler(self.bestAttemptContent);<\/code><\/pre>\n<p>Q\uff1a\u8bbe\u7f6e\u4e2d\uff0c\u63a8\u9001\u5c55\u793a\u4f4d\u90fd\u5173\u4e86\uff0c\u8fd8\u80fd\u9707\u52a8\/\u54cd\u94c3\u5417<br \/>\nA:  iOS17\u7ecf\u6d4b\u8bd5\u662f\u4e0d\u80fd\u7684\uff0c\u5f53\u4e09\u4e2a\u5c55\u793a\u4f4d\u90fd\u5173\u95ed\u540e\uff0c\u4e0a\u7ea7\u83dc\u5355\u5c31\u663e\u793a\u901a\u77e5\u5173\u4e86\u3002\u9700\u8981\u518d\u770b\u770b\u522b\u7684\u7cfb\u7edf<\/p>\n<p>Q: \u8fd8\u5b58\u5728\u54ea\u4e9b\u68d8\u624b\u7684\u95ee\u9898<br \/>\nA: \u52ff\u6270\u6a21\u5f0f\u963b\u6321\u4e0d\u4f4f\u9707\u52a8&amp;\u54cd\u94c3\uff01 \u5bf9\u4e8e\u63a8\u9001\u6a2a\u5e45\u672c\u8eab\u7684\u58f0\u97f3\uff0c\u52ff\u6270\u6a21\u5f0f\u662f\u53ef\u4ee5\u8fdb\u884c\u963b\u6321\u7684\uff0c\u4f46\u8fd9\u4e2a\u65b9\u6848\u4e2d\u7684\u9707\u52a8\u3001\u54cd\u94c3\u8d70\u7684\u662f\u4e3b\u7ebf\u7a0b\u3002\u4e14\u7cfb\u7edf\u6ca1\u6709\u66b4\u9732\u51faapi\u6765\u5224\u65ad\u5f53\u524d\u8bbe\u5907\u7684\u6a21\u5f0f\u3002\u770b\u4e86\u4e0b\u5fae\u4fe1\u8bed\u97f3\u6765\u7535\uff0c\u4e5f\u6709\u8fd9\u4e2a\u95ee\u9898...<\/p>\n","protected":false},"excerpt":{"rendered":"<p>0 \u63a8\u9001\u7684\u5206\u7c7b \u5728\u4ecb\u7ecd\u65b9\u6848\u4e4b\u524d\uff0c\u5148\u7b80\u5355\u8fc7\u4e00\u4e0bpush\u7684\u7c7b\u578b\uff1a \u53c2\u8003\uff1asending-notification-requests-to-apns?language=objc \u8fdc\u7a0b\u63a8\u9001\u7684\u5206\u7c7b\u5f88\u591a\uff0c\u8bbe\u5907\u63a5\u53d7&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,5],"tags":[16,15],"class_list":["post-69","post","type-post","status-publish","format-standard","hentry","category-ios","category-dev-tech","tag-push","tag-15"],"_links":{"self":[{"href":"https:\/\/hexiaoyang.top\/index.php\/wp-json\/wp\/v2\/posts\/69","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hexiaoyang.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hexiaoyang.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hexiaoyang.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hexiaoyang.top\/index.php\/wp-json\/wp\/v2\/comments?post=69"}],"version-history":[{"count":6,"href":"https:\/\/hexiaoyang.top\/index.php\/wp-json\/wp\/v2\/posts\/69\/revisions"}],"predecessor-version":[{"id":98,"href":"https:\/\/hexiaoyang.top\/index.php\/wp-json\/wp\/v2\/posts\/69\/revisions\/98"}],"wp:attachment":[{"href":"https:\/\/hexiaoyang.top\/index.php\/wp-json\/wp\/v2\/media?parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hexiaoyang.top\/index.php\/wp-json\/wp\/v2\/categories?post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hexiaoyang.top\/index.php\/wp-json\/wp\/v2\/tags?post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}