0

我无法弄清楚为什么应用程序崩溃,同时使用 class.insert 将数据插入数据库SQLitePersistence

从 webservice 下载产品 xml 数据后,我试图将所有产品详细信息插入到各种表中,例如,

Product 
Product_image
Product_option
Product_categories
Product_custom_option

目前,我们有 800 个产品在 webservice 上可用,未来可能会增加 2000 个左右的产品。

我的问题是:插入 400 到 450 个产品后,应用程序经常崩溃。然后我使用@autorelesepool每个循环将数据插入数据库。它会增加 500 到 550 个产品,然后应用程序崩溃,接下来我该怎么做才能避免应用程序崩溃?

我的产品表文件的SQLitePersistence数据库类:.h

#import <Foundation/Foundation.h>
#import "SQLitePersistentObject.h"

@interface iMobDB : SQLitePersistentObject
{
    NSString *sku;
    NSString *name;
    .....
    .....
}
@property(nonatomic,retain) NSString *sku;
@property(nonatomic,retain) NSString *name;
.....
.....
@end

.m文件

@implementation iMobDB

@synthesize sku;
@synthesize name;
    .....
    .....

-(void) dealloc
{
    for (NSString *one in [[self class] propertiesWithEncodedTypes])
    {
        [self removeObserver:self forKeyPath:one];
    }
    iMobReleaseNil(sku);
    iMobReleaseNil(name);
    .....
    .....
}

Appdelegate我在课堂上在这里插入数据

 /*===================================== Save Product Information ===============================================*/

        iMobDB *imobdb = [[iMobDB alloc]init];
        imobdb.productId = [productid intValue];
        imobdb.sku = skukey;
        imobdb.name = namekey;
        imobdb.optionalOption = [NSString stringWithFormat:@"%d",options];
        imobdb.requriedOption = [NSString stringWithFormat:@"%d",requried];
        imobdb.productType = producttypekey;
        imobdb.price = pricekey;
        imobdb.specialprice = specialpricekey;
        imobdb.stock = [stock intValue];
        imobdb.manufacture = manukey;
        [imobdb save];
        imobdb=nil;

        /*==============================================================================================================*/

        /*==================================== Save Product Images =====================================================*/
       __unsafe_unretained NSDictionary  *imagearray=[[dict objectForKey:@"images"] objectForKey:@"url"];

        @autoreleasepool 
        {

        for (NSDictionary *dict in imagearray)
        {
            if ([dict  isKindOfClass:[NSArray class]])
            {
                NSString *imageurl=[dict objectForKey:@"text"];                
                ImageDB *imagedb = [[ImageDB alloc] init];
                imagedb.productId = [productid intValue];
                imagedb.imageurl = imageurl;
                [imagedb save];
                imagedb=nil;
            }
            else if([dict  isKindOfClass:[NSDictionary class]])
            {
                NSString *imageurl=[dict objectForKey:@"text"];              
                ImageDB *imagedb = [[ImageDB alloc] init];
                imagedb.productId = [productid intValue];
                imagedb.imageurl = imageurl;
                [imagedb save];
                imagedb=nil;
            }
        }

        }
        /*===============================================================================================================*/

        /*==================================== Save Category ============================================================*/
        @autoreleasepool 
        {

      __unsafe_unretained  NSDictionary *categorydict = [dict objectForKey:@"categories"];

                for (NSDictionary *dictt in catedict)
                {
                 __unsafe_unretained   NSString *categoryid=[[dictt objectForKey:@"categoryId"]objectForKey:@"text"];
                __unsafe_unretained    NSString *categoryname=[[dictt objectForKey:@"categoryName"]objectForKey:@"text"];                    
                    Categories *catdb  = [[Categories alloc] init];
                    catdb.categoryId = [categoryid intValue];
                    catdb.categoryname = categoryname;
                    catdb.productId = [productid intValue];
                    [catdb save];
                    catdb=nil;
                }
            }

请注意:我在以下课程中禁用了 ARC

在此处输入图像描述

错误日志截图

在此处输入图像描述

错误日志

2 月 1 日 11:53:59 Innoppl-iPod backboardd[52]:iMob[2811] 有超过允许时间的活动断言:{(标识符:暂停进程:iMob[2811] allowedBackgroundDuration:10.000000 原因:暂停所有者 pid:52 preventSuspend preventThrottleDownCPU preventThrottleDownUI )} 2 月 1 日 11:53:59 Innoppl-iPod backboardd[52]:强制 iMob[2811] 的崩溃报告... 2 月 1 日 11:53:59 Innoppl-iPod backboardd[52]:完成崩溃报告。2 月 1 日 11:53:59 Innoppl-iPod ReportCrash [2819]:libMobileGestalt copySystemVersionDictionaryValue:无法从系统版本字典中查找 ReleaseType 2 月 1 日 11:53:59 Innoppl-iPod com.apple.launchd 1 (UIKitApplication:com.innoppl.Saletab[0xe1bf][2811]) : (UIKitApplication:com.innoppl.Saletab[0xe1bf]) 退出:杀死:2 月 1 日 11:53:59 Innoppl-iPod backboardd[52]:应用程序' UIKitApplication:com.innoppl.Saletab[0xe1bf]' 异常退出,信号 9:被杀死:9 Feb 1 11:53:59 Innoppl-iPod ReportCrash[2819] :将 crashreport 保存到 /var/mobile/Library/Logs/CrashReporter/iMob_2013 -02-01-115359_Innoppl-iPod.plist 使用 uid:0 gid:0,synthetic_euid:501 egid:0

4

0 回答 0