{"id":15846,"date":"2022-12-22T15:16:49","date_gmt":"2022-12-22T07:16:49","guid":{"rendered":"https:\/\/www.yimenapp.com\/kb-yimen\/?p=15846"},"modified":"2022-12-22T15:16:50","modified_gmt":"2022-12-22T07:16:50","slug":"%e6%9e%81%e5%85%89%e6%b6%88%e6%81%af%e6%8e%a8%e9%80%81ios-%e9%80%9a%e7%9f%a5%e7%82%b9%e5%87%bb%e8%b7%b3%e8%bd%ac","status":"publish","type":"post","link":"https:\/\/www.yimenapp.com\/kb-yimen\/15846\/","title":{"rendered":"\u6781\u5149\u6d88\u606f\u63a8\u9001iOS \u901a\u77e5\u70b9\u51fb\u8df3\u8f6c"},"content":{"rendered":"\n<p><span class=\"wpcom_tag_link\"><a href=\"https:\/\/www.yimenapp.com\/kb-yimen\/tag\/%e6%9e%81%e5%85%89\/\" title=\"\u6781\u5149\" target=\"_blank\">\u6781\u5149<\/a><\/span>\u6d88\u606f\u63a8\u9001iOS \u901a\u77e5\u70b9\u51fb\u8df3\u8f6c<\/p>\n\n\n\n<p>\u63a8\u9001\u65f6\u4e0b\u53d1\u9644\u52a0\u53c2\u6570\uff0c\u5ba2\u6237\u7aef\u83b7\u53d6\u53c2\u6570\u540e\u505a\u76f8\u5e94\u7684\u4e1a\u52a1\u8df3\u8f6c\u903b\u8f91\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u670d\u52a1\u7aef\u4f7f\u7528\">\u670d\u52a1\u7aef\u4f7f\u7528<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"\u63a7\u5236\u53f0\u4f7f\u7528\">\u63a7\u5236\u53f0\u4f7f\u7528<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"2498\" height=\"1456\" src=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/12\/20221222151629268.png\" alt=\"\" class=\"wp-image-15847\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"api-\u4f7f\u7528\">API \u4f7f\u7528<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u5173\u952e\u5b57<\/th><th>\u7c7b\u578b<\/th><th>\u9009\u9879<\/th><th>\u542b\u4e49<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td>extras<\/td><td>JSON Object<\/td><td>\u53ef\u9009<\/td><td>\u9644\u52a0\u5b57\u6bb5<\/td><td>\u8fd9\u91cc\u81ea\u5b9a\u4e49 Key \/ value \u4fe1\u606f\uff0c\u4ee5\u4f9b\u4e1a\u52a1\u4f7f\u7528\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\">          <code>\"ios\": {\n    \"alert\": \"hello, JPush!\",\n    \"badge\": 1,\n    \"extras\": {\n        \"news_id\": 134,\n        \"my_key\": \"a value\"\n    }\n}\n<\/code>\n        <\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5ba2\u6237\u7aef\u83b7\u53d6\u53c2\u6570\">\u5ba2\u6237\u7aef\u83b7\u53d6\u53c2\u6570<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"\u901a\u77e5\">\u901a\u77e5<\/h3>\n\n\n\n<p>iOS \u8bbe\u5907\u6536\u5230\u901a\u77e5\u63a8\u9001\uff08APNs \uff09\uff0c\u7528\u6237\u70b9\u51fb\u63a8\u9001\u901a\u77e5\u6253\u5f00\u5e94\u7528\u65f6\uff0c\u5e94\u7528\u7a0b\u5e8f\u6839\u636e\u8fd0\u884c\u72b6\u6001\u8fdb\u884c\u4e0d\u540c\u5904\u7406\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>App \u5728\u524d\u53f0\u8fd0\u884c\uff1a<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">          <code>- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger options))completionHandler {\n  NSDictionary * userInfo = notification.request.content.userInfo;\n  \n  UNNotificationRequest *request = notification.request; \/\/ \u6536\u5230\u63a8\u9001\u7684\u8bf7\u6c42\n  UNNotificationContent *content = request.content; \/\/ \u6536\u5230\u63a8\u9001\u7684\u6d88\u606f\u5185\u5bb9\n  \n  NSNumber *badge = content.badge;  \/\/ \u63a8\u9001\u6d88\u606f\u7684\u89d2\u6807\n  NSString *body = content.body;    \/\/ \u63a8\u9001\u6d88\u606f\u4f53\n  UNNotificationSound *sound = content.sound;  \/\/ \u63a8\u9001\u6d88\u606f\u7684\u58f0\u97f3\n  NSString *subtitle = content.subtitle;  \/\/ \u63a8\u9001\u6d88\u606f\u7684\u526f\u6807\u9898\n  NSString *title = content.title;  \/\/ \u63a8\u9001\u6d88\u606f\u7684\u6807\u9898\n  \n  <strong>if<\/strong>([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger <strong>class<\/strong>]]) {\n    [JPUSHService handleRemoteNotification:userInfo];\n    NSLog(@\"iOS10 \u524d\u53f0\u6536\u5230\u8fdc\u7a0b\u901a\u77e5:%@\", [<strong>self<\/strong> logDic:userInfo]);\n\n    [rootViewController addNotificationCount];\n  }\n  <strong>else<\/strong> {\n    \/\/ \u5224\u65ad\u4e3a\u672c\u5730\u901a\u77e5\n    NSLog(@\"iOS10 \u524d\u53f0\u6536\u5230\u672c\u5730\u901a\u77e5:{\\nbody:%@\uff0c\\ntitle:%@,\\nsubtitle:%@,\\nbadge\uff1a%@\uff0c\\nsound\uff1a%@\uff0c\\nuserInfo\uff1a%@\\n}\",body,title,subtitle,badge,sound,userInfo);\n  }\n  completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert); \/\/ \u9700\u8981\u6267\u884c\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u9009\u62e9\u662f\u5426\u63d0\u9192\u7528\u6237\uff0c\u6709Badge\u3001Sound\u3001Alert\u4e09\u79cd\u7c7b\u578b\u53ef\u4ee5\u8bbe\u7f6e\n}\n<\/code>\n        <\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>App \u5728\u540e\u53f0\u65f6\uff08\u9700\u8981\u70b9\u51fb\u901a\u77e5\u624d\u80fd\u89e6\u53d1\u56de\u8c03\uff09\uff1a<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">          <code>- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler {\n  \n  NSDictionary * userInfo = response.notification.request.content.userInfo;\n  UNNotificationRequest *request = response.notification.request; \/\/ \u6536\u5230\u63a8\u9001\u7684\u8bf7\u6c42\n  UNNotificationContent *content = request.content; \/\/ \u6536\u5230\u63a8\u9001\u7684\u6d88\u606f\u5185\u5bb9\n  \n  NSNumber *badge = content.badge;  \/\/ \u63a8\u9001\u6d88\u606f\u7684\u89d2\u6807\n  NSString *body = content.body;    \/\/ \u63a8\u9001\u6d88\u606f\u4f53\n  UNNotificationSound *sound = content.sound;  \/\/ \u63a8\u9001\u6d88\u606f\u7684\u58f0\u97f3\n  NSString *subtitle = content.subtitle;  \/\/ \u63a8\u9001\u6d88\u606f\u7684\u526f\u6807\u9898\n  NSString *title = content.title;  \/\/ \u63a8\u9001\u6d88\u606f\u7684\u6807\u9898\n  \n  <strong>if<\/strong>([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger <strong>class<\/strong>]]) {\n    [JPUSHService handleRemoteNotification:userInfo];\n    NSLog(@\"iOS10 \u6536\u5230\u8fdc\u7a0b\u901a\u77e5:%@\", [<strong>self<\/strong> logDic:userInfo]);\n    [rootViewController addNotificationCount];\n\n  }\n  <strong>else<\/strong> {\n    \/\/ \u5224\u65ad\u4e3a\u672c\u5730\u901a\u77e5\n    NSLog(@\"iOS10 \u6536\u5230\u672c\u5730\u901a\u77e5:{\\nbody:%@\uff0c\\ntitle:%@,\\nsubtitle:%@,\\nbadge\uff1a%@\uff0c\\nsound\uff1a%@\uff0c\\nuserInfo\uff1a%@\\n}\",body,title,subtitle,badge,sound,userInfo);\n  }\n  \n  completionHandler();  \/\/ \u7cfb\u7edf\u8981\u6c42\u6267\u884c\u8fd9\u4e2a\u65b9\u6cd5\n}\n<\/code>\n        <\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>App \u672a\u542f\u52a8\u72b6\u6001\uff1a<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">          <code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions; \n\/\/ apn \u5185\u5bb9\u83b7\u53d6\uff1a\nNSDictionary *remoteNotification = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey]\n<\/code>\n        <\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"\u81ea\u5b9a\u4e49\u6d88\u606f\">\u81ea\u5b9a\u4e49\u6d88\u606f<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>\u4ec5 APP \u5728\u524d\u53f0\u8fd0\u884c\u65f6\u624d\u80fd\u6536\u5230\u81ea\u5b9a\u4e49\u6d88\u606f\u7684\u63a8\u9001\u3002<\/li><li>\u4ece JPush \u670d\u52a1\u5668\u83b7\u53d6\u7528\u6237\u63a8\u9001\u7684\u81ea\u5b9a\u4e49\u6d88\u606f\u5185\u5bb9\u548c\u6807\u9898\u4ee5\u53ca\u9644\u52a0\u5b57\u6bb5\u7b49\u3002<\/li><\/ul>\n\n\n\n<p><strong>\u5b9e\u73b0\u65b9\u6cd5<\/strong><br>\u83b7\u53d6 iOS \u7684\u63a8\u9001\u5185\u5bb9\u9700\u8981\u5728 delegate \u7c7b\u4e2d\u6ce8\u518c\u901a\u77e5\u5e76\u5b9e\u73b0\u56de\u8c03\u65b9\u6cd5\u3002<br>\u5728\u65b9\u6cd5- (BOOL)<span class=\"wpcom_keyword_link\"><a href=\"https:\/\/www.yimenapp.com\" target=\"_blank\" title=\"\u5f00\u53d1app\u4ece\u4e00\u95e8\u5f00\u59cb\">app<\/a><\/span>lication:(UIApplication _)application didFinishLaunchingWithOptions:(NSDictionary _) launchOptions \u52a0\u5165\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">          <code>NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];\n[defaultCenter addObserver:<strong>self<\/strong> selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil];\n<\/code>\n        <\/pre>\n\n\n\n<p>\u5b9e\u73b0\u56de\u8c03\u65b9\u6cd5 networkDidReceiveMessage<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">          <code>- (<strong>void<\/strong>)networkDidReceiveMessage:(NSNotification *)notification {\n    NSDictionary * userInfo = [notification userInfo];\n    NSString *content = [userInfo valueForKey:@\"content\"];\n    NSString *messageID = [userInfo valueForKey:@\"_j_msgid\"];\n    NSDictionary *extras = [userInfo valueForKey:@\"extras\"]; \n    NSString *customizeField1 = [extras valueForKey:@\"customizeField1\"]; \/\/\u670d\u52a1\u7aef\u4f20\u9012\u7684 Extras \u9644\u52a0\u5b57\u6bb5\uff0ckey \u662f\u81ea\u5df1\u5b9a\u4e49\u7684  \n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u63a8\u9001\u65f6\u4e0b\u53d1\u9644\u52a0\u53c2\u6570\uff0c\u5ba2\u6237\u7aef\u83b7\u53d6\u53c2\u6570\u540e\u505a\u76f8\u5e94\u7684\u4e1a\u52a1\u8df3\u8f6c\u903b\u8f91<\/p>\n","protected":false},"author":1,"featured_media":15847,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[656],"tags":[157,7385,562],"special":[],"attr":[],"class_list":["post-15846","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-app36","tag-apptuisong","tag-7385","tag-jiguangtuisong","entry"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts\/15846","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/comments?post=15846"}],"version-history":[{"count":1,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts\/15846\/revisions"}],"predecessor-version":[{"id":15848,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts\/15846\/revisions\/15848"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/media\/15847"}],"wp:attachment":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/media?parent=15846"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/categories?post=15846"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/tags?post=15846"},{"taxonomy":"special","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/special?post=15846"},{"taxonomy":"attr","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/attr?post=15846"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}