A strange crash without crashing report

30 views
Skip to first unread message

Wang York

unread,
Dec 4, 2019, 4:44:14 PM12/4/19
to FMDB

The crash is quite strange, it has no crash report on Xcode or other third part analyze sdks, only happens on less than 1% users. When it happened, it keeps crashing on launch(Because my app updates database on launch), users have to reinstall the app, after several days, it happens again on the same users. It's caused by below code. When I removed below updating database code or let user delete and recreate the database, users said the crashing issue was gone:

    + (void)updateFMDBByUpdateIndexJson:(IndexItemJson *)updateIndexJson fmdb:(FMDatabase *)db
    {
        if (![db open]) {
            NSLog(@"%@ open failed",@"update");
        }
        if ([updateIndexJson countOfIndexItems] == 0) {
            return;
        }
        NSArray *mangaNameArray = [[updateIndexJson mangaItems] valueForKey:KJsonIndexMangaName];
      
        NSString *test = @"(?";
        for (int i = 1; i< mangaNameArray.count; i++) {
            test = [[test stringByAppendingString:@","] stringByAppendingString:@"?"];
        }
        test = [test stringByAppendingString:@")"];
        test = [NSString stringWithFormat:@"delete from mangas where name in %@",test];
        @try {
            [db executeUpdate:test withArgumentsInArray:mangaNameArray];
        } @catch (NSException *exception) {
    //        NSLog(@"Delete Rows Error %@: %@", [exception name], [exception reason]);
            NSString *msg = [NSString stringWithFormat:@"Delete Rows NSException %@: %@", [exception name], [exception reason]];
        } @finally {
            
        }



        //add update index items to db
        NSString* strCreateTable = @"create table mangas (name text, author text, cover text, latest text, mJLink text, r text, rn integer, isOn boolean, genres text)";
        if (![db executeUpdate:strCreateTable]) {
            NSLog(@"create table failed or table existed");
        };
        
        if ([db tableExists:@"mangas"] && ![db columnExists:@"genres" inTableWithName:@"mangas"]) {
            [db executeUpdate:@"ALTER TABLE mangas ADD COLUMN genres TEXT"];
        }
         
        [db beginTransaction];
        
        BOOL isRollBack = NO;
        @try {
            for (int i=0; i<[indexJson countOfIndexItems]; i++) {
                NSString *name = [indexJson mangaNameByIndex:i];
                NSString *author = [indexJson authorByIndex:i];
                NSString *cover = [indexJson coverUrlByIndex:i];
                NSString *mjlink = [indexJson mangaJLinkByIndex:i];
                NSString *rate = [indexJson rateByIndex:i];
                NSNumber *rn = [indexJson rateCountByIndex:i];
                NSString *latest = [indexJson latestChByIndex:i];
                NSString *genres = [indexJson genresByIndex:i];
                NSNumber *isOn = [indexJson isOnByIndex:i];
                [db executeUpdate:@"insert into mangas (name, author, cover, latest, mJLink, r, rn, isOn, genres) values (?, ?, ?, ?, ?, ?, ?, ?, ?)",name,author,cover,latest,mjlink,rate,rn,isOn,genres];
            }
        } @catch (NSException *exception) {
            isRollBack = YES;
            [db rollback];
            NSString *msg = [NSString stringWithFormat:@"Insert Rows NSException %@: %@", [exception name], [exception reason]];
            NSLog(@"%@", msg);
        } @finally {
            if (!isRollBack) {
                [db commit];
            }
            [db close];
        }    

    }

It's executed like below:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    NSSet *websiteSet = [AppDelegate validSourcesFromFav];
    for (NSString *website in websiteSet) {
        
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSString *updateIndexUrl = [StaticParameters getUpdateIndexJlinkByWebsite:website];
            if (updateIndexUrl) {
                    NSData *data = [Common urlCollectionSynchronousWithRefer:[StaticParameters getMangaRefer] url:updateIndexUrl];
                    IndexItemJson *indexJson = [[IndexItemJson alloc] initWithData:[data gunzippedData]];
                    
                    //update database
                    dispatch_async([self serialQueue], ^{
                        
                        FMDatabase *db = [AppDelegate initDB:website];
                        if ([db columnExists:@"genres" inTableWithName:@"mangas"]) {
                            [AppDelegate updateFMDBByUpdateIndexJson:indexJson fmdb:db];
                        }

                    });
            }
        });
    }
    
}

Using latest version of FMDB didn't fix it, and this issue only happens on iOS 12 & 13, It can't be fixed for more than one year. Hope you guys can help me!
Thank you very much!

Reply all
Reply to author
Forward
0 new messages