Currently, I am conducting research and development on integrating a pubnub access manager in swift. Upon investigation, I discovered the following:
- The Swift SDK does not have pubnub.grant functionality.
- To accomplish this, I must utilize a pubnub function for serverless computing.
I have set up a function in the pubnub dashboard under the module PubNub, with an event type of "On Request", and included the grant code.
export default (request, response) => {
const pubnub = require('pubnub');
const kvstore = require('kvstore');
let headersObject = request.headers;
let paramsObject = request.params;
let methodString = request.method;
let bodyString = request.body;
response.headers['Access-Control-Allow-Origin'] = '*';
response.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept';
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, OPTIONS, PUT, DELETE';
response.headers['Content-Type'] = 'application/json';
var uuid = 'aartisagarvadgama'
return pubnub.grant({
channels: ['channel_atts_pubnub'],
read: true,
write: false,
authKeys: [uuid],
ttl: 0
}).then(() => {
console.log('grant success')
response.status = 200;
return response.send(uuid);
}).catch((error) => {
console.log(error);
response.status = 400;
return response.send();
});
};
Although I can successfully invoke this function by copying the URL and receiving a success code, I am unsure how to implement this in my iOS application.
Please advise me on any method to incorporate the access manager into my app.
Based on my understanding, establishing a function to grant the user access is necessary. Upon calling this function, I should be able to subscribe or publish content without encountering a 403 error. Any assistance would be highly appreciated. Please offer guidance.