0

i have an old app in objective C using cloudcode to send pushes to back4app platform.

The app manage to send correctly the pushes and this is the code :

- (IBAction)inviaPush:(UIButton *)sender {
   NSString *canale;
   for (int i=0; i<=4; i++) {
       switch (i) {
           case 0:canale=@"TraduzioniEDI";
               break;
           case 1:canale=@"NavFtpYM";
               break;
           case 2:canale=@"InvioMailFTP";
               break;
           case 3:canale=@"VermasMto";
               break;
           case 4:canale=@"EdiAltova";
               break;
           default:
                break;
       }
       NSString *testoPush =[NSString stringWithFormat:@"%@ Test Invio %@",  canale,[NSDate date]];
        [PFCloud callFunctionInBackground:@"push"
                          withParameters:@{@"channels": @[canale], @"data": @{@"alert": testoPush,@"badge":@"Increment"}}
                                   block:^( NSString *result, NSError *error) {
                                       if (!error) {
                                           NSLog(@"Risultato: %@",result);
                                       } else{
                                           NSLog(@"Errore %@",error);
                                       }
                                   }];
   }
}

Running the code i receive the 5 pushes and in the info of back4app dashboard i find :

2020-03-02T01:14:53.533Z - Ran cloud function push for user undefined with: Input: {"channels":["VermasMto"],"data":{"alert":"VermasMto Test Invio 2020-03-02 01:14:52 +0000"}} Result: "Sent!!"

i tried to convert the program in swift the code to send push is :

func inviaPush (){
   var canale :String = ""
   for i in 0...4
   {
       switch i {
       case 0: canale = "TraduzioniEDI"
       case 1: canale = "NavFtpYM"
       case 2: canale = "InvioMailFTP"
       case 3: canale = "VermasMto"
       case 4: canale = "EdiAltova"
       default: canale=""
       }
       let testoPush = "\(canale) Test invio - Swift"
       PFCloud.callFunction(inBackground: "push", withParameters: ["channels": canale, "data": ["alert": testoPush,"badge":"Increment"]], block: {
            (result: Any?, error: Error?) -> Void in
            if error != nil {
               if let descrip = error?.localizedDescription{
                   print(descrip)
               }
           }else{
               print(result as! String)
           }
        })
   }
}

in this case i receive no pushes, and in the info i find following : 2020-03-02T01:17:25.505Z - Ran cloud function push for user undefined with: Input: {"channels":"NavFtpYM","data":{"alert":"NavFtpYM Test invio"}} Result: "Sent!!"

2020-03-02T01:17:25.504Z - Can't count installations for PushStatus hm5hbCzDvd: bad $in value

Comparing the info shown in the dashboard i see a difference in input

in ojective C (Working) the in input the channel have a square bracket :

Input: {"channels":["VermasMto"],

while when sent from swift they have not

Input: {"channels":"NavFtpYM",

surely i'm calling the method PFCloud.callFunction in a wrong way.

Any suggestion ?

Fabrizio

Grisu70
  • 57
  • 5

1 Answers1

1

the solution was simple ...

need to change

PFCloud.callFunction(inBackground: "push", withParameters: ["channels": canale, "data": ["alert": testoPush,"badge":"Increment"]], block: {

in

PFCloud.callFunction(inBackground: "push", withParameters: ["channels": [canale], "data": ["alert": testoPush,"badge":"Increment"]], block: {

Fabrizio

Grisu70
  • 57
  • 5