简体   繁体   中英

RestiKit makes iPhone too slow while downloading

I'm connecting via WIFI from my iPhone to a webService installed locally on my Mac.

I load four sets of data into a TableView each one with a different request. After the first download in done, I load the data into the TableView and continue with the following downloads.

While RestKit is working the app is nearly dead. You just can barely scroll the TableView, and have to wait until the download process is finished to be able to work.

How can I make RestKit not so heavy on my device so I can quietly download data while working?

EDIT:

I have notice when running in device the following message in console:

warning: Unable to read symbols for /Users/david/Library/Developer/Xcode/iOS DeviceSupport/4.2.1 (8C148)/Symbols/usr/lib/info/dns.so (file not found).
warning: No copy of dns.so found locally, reading from memory on remote device.  This may slow down the debug session.

I'm still trying to get the meaning.

AppDelegate. I init a AEMEventosList and invoke downloadEventos method to start downloading.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.   


    //Original code
    AEMMasterViewController *masterViewController = [[[AEMMasterViewController alloc] initWithNibName:@"AEMMasterViewController" bundle:nil] autorelease];

    //Inicializar lista de eventos
    AEMEventosList *aux = [[AEMEventosList alloc] init];
    aux.delegate = masterViewController;

    //Asignar la lista de eventos a la variable miembro de la clase
    self.eventosList = aux;
    [aux release];

    // Comenzar la descarga de eventos desde el servidor
    [self.eventosList downloadEventos];

    //Orignal code
    self.navigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];
//    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.71 green:0.45 blue:0.05 alpha:1];
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];


    return YES;
}

AEMEventosList inti method:

-(id)init {
    self = [super init];
    if (self) {    
        self.eventos = [NSMutableDictionary dictionary];
        self.downloadingEventosGroupFlag = 0;
        self.eventosGroupNames = [NSArray arrayWithObjects:
                                             kEventosToday, 
                                             kEventosInAWeek, 
                                             kEventosInAMonth, 
                                             kEventosLaterThanAMonth, 
                                             nil];

        //Iniciar el manager
        self.manager = [RKObjectManager objectManagerWithBaseURL:kRestURL];

        //Mapeo de atributos JSON a miembros de la clase AEMEvento
        RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[AEMEvento class]];
        [mapping mapAttributes:
         kIdEvento,
         kNombreEvento,
         kEntradilla,
         kDescripcion,
         kDiaDeInicio,
         kDiaDeFin,
         kHorarioTexto,
         kIdFuente,
         kNombreFuente,
         kFotoURL,
         kWebURL,
         kUbicaciones,
         kHorarios,
         kDiaDeInicioYFinTexto,
         nil];


        //Especificar el mapeo de fechas
        NSDateFormatter* dateFormatter = [NSDateFormatter new];
        [dateFormatter  setDateFormat:kDateFormatStringForJson];
        [dateFormatter setTimeZone:[NSTimeZone defaultTimeZone]];
        mapping.dateFormatters = [NSArray arrayWithObject:dateFormatter];
        [dateFormatter release];    

        //Asignar el mapeo al manager siempre que se encuentre la clave "eventos" en el archivo JSON
        [self.manager.mappingProvider setMapping:mapping forKeyPath:kEventos];        
    }
    return self;
}

AEMEventosList downloadEventos method

-(void)downloadEventos {            

    //Iniciar la descarga del grupo de eventos indicado por el atributo downloadingEventosGroupFlag
    [self.manager loadObjectsAtResourcePath:[self.eventosGroupNames objectAtIndex:self.downloadingEventosGroupFlag] delegate:self];

    //Enviar al delegado el mensaje de incio de descarga para que muestre la vista con el indicador de progreso.
    [self.delegate AEMEventosListDidStartLoadingEventos:self];

}

Table View Delegate Mehods:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [self.eventosList.eventos count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[self.eventosList.eventos objectForKey:[self.eventosList.eventosGroupNames objectAtIndex:section]] count];
}

    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return 80;
    }

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    switch (section) {
        case 0:
            return NSLocalizedString(@"Today", @"Today's events tableview section title.");
            break;
        case 1:
            return NSLocalizedString(@"In a week", @"In a week's events table view section title.");
            break;
        case 2:
            return NSLocalizedString(@"In a month", @"In a month's events tableview section title.");
            break;
        case 3:
            return NSLocalizedString(@"Later than a month" , @"Later than a month events tableview section title.");
            break;
        default:
            return nil;
            break;
    }

}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    //Obtener el evento de la lista para la celda
    NSArray *aux = [self.eventosList.eventos objectForKey:[self.eventosList.eventosGroupNames objectAtIndex:indexPath.section]];
    AEMEvento *auxEvento = [aux objectAtIndex:indexPath.row];


    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;        

        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        cell.textLabel.textColor = [UIColor colorWithRed:0.2 green:0.3 blue:0.5 alpha:1];
        cell.textLabel.font = [UIFont systemFontOfSize:13];
        cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
        cell.textLabel.numberOfLines = 2;

        cell.detailTextLabel.textColor = [UIColor lightGrayColor];
        cell.detailTextLabel.font = [UIFont systemFontOfSize:11];
        cell.detailTextLabel.textAlignment = UITextAlignmentRight;
    }

    // Configure the cell.
    cell.textLabel.text = auxEvento.nombreEvento;
    cell.detailTextLabel.text = auxEvento.diaDeInicioYFinTexto;
    NSString *path = [[NSBundle mainBundle] pathForResource:@"iconGijonBlanco" ofType:@"png"];
    cell.imageView.image = [UIImage imageWithContentsOfFile:path];  
    return cell;
}

// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return NO;
}

Can you post the code you are using to call the requests as well as the code you are using to process the request when it is finished? Without seeing that, it sounds like you are instantiating the requests and running them on the main thread instead of using async and passing the requests to a background thread.

RestKit have nothing to do with the problem. After loading the data I have a loop processing each element downloaded (about 400 times). While the simulator could loop 100 times per second the device only can handle 4 per second. I have to search what's happening, but I will open a new thread on this since is a different problem than the original.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM