Skip to main content

Register New user to xmpp/Openfire in Objective-c

 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@",self.mobileNoTF.text],@"username",[NSString stringWithFormat:@"%@",self.PasswordTF.text],@"password",[NSString stringWithFormat:@"%@",self.FnameTF.text],@"name", nil];
    NSData* RequestData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:nil];
    
    NSMutableURLRequest *request = [ [ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString:[NSString stringWithFormat:@"http://178.238.235.183:9090/plugins/restapi/v1/users"]]];
    
    
    [request setHTTPMethod: @"POST"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [request setValue:@"xR7VARchjfhriVc6" forHTTPHeaderField:@"Authorization"];
    [request setHTTPBody: RequestData];
    
    NSURLSession *session = [NSURLSession sharedSession];
    [[session dataTaskWithRequest:request
                completionHandler:^(NSData *data,
                                    NSURLResponse *response,
                                    NSError *error) {
                    // handle response
                    if (!error)
                    {
                        
                        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                        if ([httpResponse statusCode]==201)
                        {
                            
                            NSLog(@"Registration Successfully");
                            
                        }else
                        {
                            NSLog(@"Registration failed");
                        }
                        
                    }else
                    {
                        NSLog(@"Try again for registration");
                    }
                    
                    
                }] resume];

   
REST API:- http://178.238.235.183:9090/plugins/restapi/v1/users
Secret Key:- 
xR7VARchjfhriVc6

Comments

Post a Comment

Popular posts from this blog

post method using alamofire in swift 3

  func addSubscriptionApi(_completeUrl: String ) {         //HUD         Alamofire.request(_completeUrl, method:.post, parameters: nil , encoding: JSONEncoding. default , headers: nil ).responseJSON { response in             switch (response.result) {             case .success( _ ):                 if let data = response.result.value as ? NSDictionary                 {                     print(response.result.value as Any)                     print(data)                      print("SUCCESS")                  }                 break  ...

Call phone Number In swift 3

//Here you can make method of calling functionality. func callNumber (yourP honeNumber : String ) { if let phoneCallURL = URL ( string : "tel://\(yourP honeNumber )" ) { let application : UIApplication = UIApplication . shared if ( application . canOpenURL ( phoneCallURL )) { application . open ( phoneCallURL , options : [:], completionHandler : nil ) } } } Happy Coding :)