0

Ich entwickle eine iOS-App mit IBM MobileFirst Platform 8.0 sdk, die Push-Benachrichtigungsfunktionen habenIBM Mobile First Platform - Senden Push-Benachrichtigung von Adapter

ich Benachrichtigung per Postbote schicken verwaltet, war der Prozess ein Token zu erhalten aus die MobileFirst Plattform Server und die Benachrichtigung über Rest api senden zusammen mit dem Token

das Tutorial Link ich habe folgen ist,

Server Side - https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/notifications/sending-notifications/

Client Side - https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/notifications/handling-push-notifications/cordova/

Token Get - https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/authentication-and-security/confidential-clients/#obtaining-an-access-token

Vorerst ich versuche, eine Push-Benachrichtigung zu senden, wenn die App einen Adapter Anruf

ich auf das Senden der Benachrichtigung bin derzeit stecken löst mit WL.Server.invokeHttp, ist weiter unten noch mehr Adaptercode

function sendPushNotification(message) {  
    var result = getToken();  
    var access_token = "Bearer " + result["access_token"];  

    var requestStructure = { 
     method : 'post', 
     returnedContentType : 'json', 
     path : '/imfpush/v1/apps/my.app/messages', 
     headers: { 
      "Content-Type" : "application/json", 
      "Authorization" : access_token 
     }, 
     parameters : { 
      'message':{'alert' : 'Test message'} 
     } 
    }; 

    result = MFP.Server.invokeHttp(requestStructure); 

    return result; 
} 


function getToken() { 
    var requestStructure = { 
     method : 'post', 
     returnedContentType : 'json', 
     path : '/mfp/api/az/v1/token',  
     headers: { 
      "Content-Type" : "application/x-www-form-urlencoded", 
      "Authorization" : "Basic UHVzaE5vd213123asdsadGlvbjpQdXNoTm90aasdasdWZpY2F0aW9u" 
     }, 
     parameters:{ 
      "grant_type" : "client_credentials", 
      "scope" : "push.application.my.app messages.write" 
     } 
    }; 

    var results = MFP.Server.invokeHttp(requestStructure); 
    return results; 
} 

ich auf

Problem mit scheint
parameters : { 
    'message':{'alert' : 'Test message'} 
} 

Ich könnte es auf diesem Teil falsch gemacht haben, hoffe auf Rat.

Vielen Dank im Voraus

+0

Sie scheinen Ziel im JSON zu fehlen: https://www.ibm.com/support/knowledgecenter/SSHS8R_8.0.0/com .ibm.worklight.apiref.doc/rest_runtime/r_restapi_push_message_post.html –

Antwort

0

Die sendPushNotification Methode eine falsche Syntax für den Aufruf von WS in Mobile First verwenden. Sie trüben es wie folgt ändern:

function sendPushNotification(message) {  
var result = getToken();  
var access_token = "Bearer " + result["access_token"];  

var requestStructure = { 
    method : 'post', 
    returnedContentType : 'json', 
    path : '/imfpush/v1/apps/my.app/messages', 
    headers: { 
     "Authorization" : access_token 
    }, 
    body: { 
     content: 'message':{'alert' : 'Test message'}, 
     contentType: 'application/json' 
    } 
}; 

result = MFP.Server.invokeHttp(requestStructure); 

return result; 

}

Verwandte Themen