를 사용하여 APNS에 JSON을 보내기? 샘플 코드를 제공해주세요. 여기에 알림을 작성하는 예가 나와 있습니다.이 같은 IOS 장치에 JSON을 보낼 필요가 푸시 샤프 라이브러리
답변
보내려하는 JSON이 유효하지 않습니다. 사전에 aps
사전에 사용자 지정 속성을 넣을 수 없습니다. 사용자 정의 데이터를 보내려면 , 당신은이처럼 aps
사전 외부로 보내야합니다 : 당신은 당신이 페이로드에 사용자 정의 데이터를 추가 허용 PushSharp 라이브러리에있는 방법을 찾아야한다
{"aps":{},"content-available":1}
.
프로 바이더는 Apple 예약 aps 네임 스페이스 외부에서 사용자 정의 페이로드 값을 지정할 수 있습니다. 맞춤 값은 사전 (객체), 배열, 문자열, 숫자 및 부울과 같은 JSON 구조 및 기본 유형을 사용해야합니다.
편집 :
당신은 AppleNotificationPayload
의 AddCustom(string key, params object[] values)
방법을 사용할 수 있습니다.
Eran이 언급했듯이 PushSharp를 사용하면 사용자 지정 페이로드 매개 변수를 APC 외부로 보낼 수만 있습니다. 당신이 뭔가를 보내 싶어한다면 :
// Add these to your references
using System.IO;
using PushSharp;
using PushSharp.Apple;
using PushSharp.Core;
//Create our push services broker
var push = new PushBroker();
//Registering the Apple Service and sending an iOS Notification
var appleCert = File.ReadAllBytes(string.Format(@"applePushCert.p12"));
push.RegisterAppleService(new ApplePushChannelSettings(appleCert, "password"));
push.QueueNotification(new AppleNotification()
.ForDeviceToken("your device token")
.WithAlert("Hello World!")
.WithBadge(7)
.WithSound("sound.caf")
.WithCustomItem("content-available", 1));
이 오래된 스레드,하지만 난 그냥 2015에서 검색하고 찾을 수 없습니다 :
{"aps":{ whatever data... },"content-available":1}
당신은 다음과 같이 수행 할 수 있습니다 스택 오버 플로우에 대한 해결책. 난 당신이 "콘텐츠 가능한"는 APS의 INSIDE을 포함해야
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void(^(UIBackgroundFetchResult))completionHandler
방법을 사용하기로 질문은 지금, 답변을받을 권리가 생각합니다.
(see this excellent article for details) 그래서 같은 알림의 끝에 notification.WithContentAvailable(1)
을 압정 할 수 있도록함으로써 이에 대한 그 pushsharp의 수용합니다 발견 : 픽업
var notification = new AppleNotification(deviceID1, payload1);
notification.WithContentAvailable(1);//enable background fetch
iOS 및 didReceiveRemoteNotification 방법 안쪽이 사용자 정의 항목을 선택합니다. 이것을 사용하십시오 : NSString * contentId = [userInfo objectForKey : @ "content-available"]; –