Webservices and Cache manager

Use the Apps Panel iOS SDK to communicate with your backend.

The iOS Apps Panel SDK provides the easiest way to communicate with your web services. It implements the main http methods so you can take full advantage of the RESTful API provided by the Apps Panel back end.

Making your first call

πŸ“˜

In order for you to be able to make web services calls, your app must be configured. For help on how to do this, see Getting started.

APWSManager works with a delegate, so you must first declare the class in which you want to do WS calls as APWSManagerDelegate. This protocol has two recommended methods:

- (void)apwsFailedDownload:(APWSManager *)apws;
- (void)apwsFinishedDownload:(APWSManager *)apws;
func apwsFailedDownload(_ apws: APWSManager!)
func apwsFinishedDownload(_ apws: APWSManager!)

We will come back to them later. Once your class is declared as APWSManagerDelegate, you can start writing code to make API calls.

- (void)getNewsForUser:(User*)user {
  
 //We create an APWSManager object, with the route /news, 
 //a get dictionary which will be sent as URL paramteters.
 //The tag is used to identify the request.
  
	APWSManager *apws =  [[APWSManager alloc] initWithRest:@"news" 
                        delegate:self 
												WithGet:@{@"id" : user.id} 	
                        andTag:1000];
	
  //Once the object is created, we can start the request
  [apws start];
}
func getNewsFor(user: User) {
  //We create an APWSManager object, with the route /news,
  //a get dictionary which will be sent as URL paramteters.
  //The tag is used to identify the request.
  let apws: APWSManager = APWSManager(rest: "news", delegate: self, withGet: ["id":"user_id"], andTag: 1000)
  //Once the object is created, we can start the request
  apws.start()
}

Managing answers

You must implement two methods to managers the answers, namely apwsFailedDownload and apwsFinishedDownload. The "Failed" method manages failed calls (like one that has timed out, or a 404 error), and the "Finish" method successful ones.

In each of these methods, use the tags to identify the requests.

- (void)apwsFailedDownload:(APWSManager *)apws {
	if (apws.tag == 1000) {
  	NSLog(@"%@", apws.error);
  }
}

- (void)apwsFinishedDownload:(APWSManager *)apws {
	if (apws.tag == 1000 {
  	NSArray *news = apws.result;
    //Manage the result as you wish
  }
}

Sending files

The APWSManager allows you to send files. To do so, Use the property listFiles. Each file must correspond to a NSDictionary containing a name, a filename and the data of the file.

- (void)createNewFolder(NSString *)folderName withImages:(NSArray*)images {
  
  NSMutableArray *filesToSend = [NSMutableArray array];
  int fileNumber = 1;
  
  //First, we create the array of dictionaries
  for(NSData *image in images) {
  	NSMutableDictionary *imageDictionary = [NSMutableDictionary dictionary];
    
    NSString *imageName = [NSString stringWithFormat:@"image_%d",fileNumber];
    NSString *fileName = [NSString stringWithFormat:@"image%d.jpg", filenumber];
    
    [imageDictionary setObject:image forKey:@"Data"];
    [imageDictionary setObject:imageName forKey:@"Name"];
    [imageDictionary setObject:fileName forKey:@"FileName"];
		
    [filesToSend addObject:imageDictionary];
  }
  
  //Then, we create our APWSManager object
  APWSManager *apws =  [[APWSManager alloc] initWithRest:@"images" 
                        delegate:self 
												WithGet:nil
                        andPost:@{@"folder_name" : folderName}
                        andTag:1000];
	
  //Finally, we add the files to the APWSManager object, and we start the request.
	[apws setListFiles:filesToSend];
	[apws start];
}

❗️

Files extensions

Your filename must include the extension of the file you want to send

Cache management

You can manage app-side cache thanks to cache-control http headers.

Options

There are multiple options for the APWSManager that you can enable or not.