Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can`t call delegate functions #107

Open
caraldel opened this issue Jul 3, 2015 · 0 comments
Open

Can`t call delegate functions #107

caraldel opened this issue Jul 3, 2015 · 0 comments

Comments

@caraldel
Copy link

caraldel commented Jul 3, 2015

HI !!

I`m using the classes to load RSS news. I sued to do it in background, to save the items that I get into the app BD. The parser it calls but the functions to detect when is finished never be call. This is the code:

  -(void)parseaNoticias:(NSString *)feedURLString{
  @autoreleasepool {

    @try {

        NSURL *feedURL = [NSURL URLWithString:feedURLString];
        parsedItems = [[NSMutableArray alloc] init];

        alerta = [[UIAlertView alloc] initWithTitle:AMLocalizedString(@"cargando", @"")
                                            message:@"\n"
                                           delegate:self
                                  cancelButtonTitle:nil
                                  otherButtonTitles:nil];


        [alerta show];

        feedParser = [[MWFeedParser alloc] initWithFeedURL:feedURL];
        feedParser.delegate = self;
        feedParser.feedParseType = ParseTypeFull; // Parse feed info and all items
        feedParser.connectionType = ConnectionTypeAsynchronously;
        [feedParser parse];

        [alerta dismissWithClickedButtonIndex:0 animated:YES];


    }
    @catch (NSException *e){
        NSLog(@"Exception %@",e);
    }
}

  }
  #pragma mark -
  #pragma mark MWFeedParserDelegate

  - (void)feedParserDidStart:(MWFeedParser *)parser {
    NSLog(@"Started Parsing: %@", parser.url);
  }

  - (void)feedParser:(MWFeedParser *)parser didParseFeedInfo:(MWFeedInfo *)info {
    NSLog(@"Parsed Feed Info: “%@”", info.title);

  }

  - (void)feedParser:(MWFeedParser *)parser didParseFeedItem:(MWFeedItem *)item {
    NSLog(@"Parsed Feed Item: “%@”", item.title);
      if (item) [parsedItems addObject:item];
  }

  - (void)feedParserDidFinish:(MWFeedParser *)parser {
    NSLog(@"Finished Parsing%@", (parser.stopped ? @" (Stopped)" : @""));

[parsedItems sortedArrayUsingDescriptors:[NSArray arrayWithObject:[[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO]]];
NSString *currentL = [Global sharedMySingleton].test;
NSMutableArray *listaNoticias = [NSMutableArray array];
NSLog(@"Items parseados : %lu", (unsigned long)[parsedItems count]);
for (int i = 0; i < [parsedItems count]; i++) {

    MWFeedItem *item = [parsedItems objectAtIndex:i];

    if (item) {

        // Process
        NSString *itemTitulo = item.title ? [item.title stringByConvertingHTMLToPlainText] : @"[No Title]";
        NSString *itemDescripcion= item.summary ? [item.summary stringByConvertingHTMLToPlainText] : @"[No Summary]";

        NSString * itemFecha = [[NSString alloc]init];
        if (item.date){
            NSDateFormatter *formatter;
            itemFecha = [formatter stringFromDate:item.date];
        } else {
            itemFecha = @"[No date]";
        }
        NSString * itemUrl = item.link ? :@"[No link]";
        // Set

        NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"titulo", itemTitulo, @"descripcion", itemDescripcion, @"fecha", itemFecha, @"url", itemUrl, @"idioma", currentL, nil];
        NSLog(@"NOT:: %@", dict);
        Noticias_DTO *noticia_dto = [[Noticias_DTO alloc]initWithNoticia:dict];
        [listaNoticias addObject:noticia_dto];
    }
}

//INSERTA EN LA BASE DE DATOS!!!

if ([listaNoticias count] > 0) {

    Noticias_DAO *not_dao = [[Noticias_DAO alloc] init];
    [not_dao InsertarNoticias:listaNoticias];
}

m_stopRunLoop = TRUE;

  }

  - (void)feedParser:(MWFeedParser *)parser didFailWithError:(NSError *)error {

NSLog(@"Finished Parsing With Error: %@", error);
m_stopRunLoop = TRUE;
if (parsedItems.count == 0) {
    NSLog(@"No hay items que parsear"); // Show failed message in title
} else {
    // Failed but some items parsed, so show and inform of error
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Parsing Incomplete"
                                                    message:@"There was an error during the parsing of this feed. Not all of the feed items could parsed."
                                                   delegate:nil
                                          cancelButtonTitle:@"Ok"
                                          otherButtonTitles:nil];
    [alert show];
}

  }

  - (void)dealloc {

alerta.delegate = nil;
  }

What I'm doing wrong ?? I put in my .h class the delegate like this:

  @interface Noticias_pasarela : NSObject <MWFeedParserDelegate>{

  // Parsing
   MWFeedParser *feedParser;
   NSMutableArray *parsedItems;

  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant