iOS在自定义Project对象的notes数组中使用addObject抛错
错误信息:-[NSNull mutableCopyWithZone:]: unrecognized selector sent to instance 0x1a0c5cea8
错误定位: [object addObject:note forKey:@"notes"];

代码:

- (void)request_CreateNote_WithProject:(NSString *)projectId text:(NSString *)text photos:(NSArray *)photos type:(NSNumber *)type block:(AVBooleanResultBlock)block {
    NSMutableArray *pic_urls = [NSMutableArray array];
    NSError* theError;
    for(TweetImage* photo in photos){
        AVFile* photoFile=[AVFile fileWithData:UIImagePNGRepresentation(photo.image)];
        [photoFile save:&theError];
        if(theError==nil){
            [pic_urls addObject:photoFile];
        }else{
            for(AVFile* file in pic_urls){
                [file deleteInBackground];
            }
            return;
        }
    }
    
    AVObject *note = [AVObject objectWithClassName:@"Note"];
    [note setObject:text forKey:@"text"];
    [note setObject:pic_urls forKey:@"pic_urls"];
    AVUser *avuser = [AVUser currentUser];
    [note setObject:avuser forKey:@"responsible"];
    [note setObject:type forKey:@"type"];
    [note saveInBackgroundWithBlock:^(BOOL succeeded , NSError *error){
        if (succeeded) {
            AVObject *object = [AVQuery getObjectOfClass:@"Project" objectId:projectId];
            [object addObject:note forKey:@"notes"];
            [object setObject:type forKey:@"processing"];
            [object saveInBackgroundWithBlock:block];
        }else{
            block(NO,error);
        }
    }];
}

你好,我没办法重现你的问题,请提供一下详细的日志以及具体的报错堆栈。
打开日志的方法:
[AVOSCloud setAllLogsEnabled:YES];

2016-04-05 11:18:25.527 RunTai[3248:1575388] [DEBUG] -[LCCurlScheduler logCurlOperation:] [Line 80]

------ BEGIN LeanCloud REST Request ------
path: /1.1/always_collect
curl: curl -i -k --compressed -X POST -H 'User-Agent: AVOS Cloud iOS-v3.2.7 SDK' -H 'Content-Type: application/json; charset=utf-8' -H 'Accept: application/json' -H 'X-LC-Id: DAnhL7gnMRhoEifbTM4xII29-gzGzoHsz' -H 'X-LC-Sign: db53834eeb824d6b15beb3b7d48a70c9,1459826305525' -H 'X-LC-Session: jo2vqbj6q6v6fck32w4npmra2' -H 'X-LC-Prod: 1' -d '{"attributes":{"total":3,"200":3,"avg":0.4001859724521637},"client":{"app_version":"1.0","id":"E6950F8C-484D-422F-9CCD-7C7895D45562","sdk_version":"v3.2.7","platform":"iOS"}}' "https://api.leancloud.cn/1.1/always_collect"
------ END -------------------------------

2016-04-05 11:18:43.055 RunTai[3248:1575289] -AGEmojiKeyboardView emojis: File read
2016-04-05 11:18:43.056 RunTai[3248:1575289] -AGEmojiKeyboardView numberOfPagesForCategory:inFrameSize:: 3 7 80 :: 4
2016-04-05 11:19:09.374 RunTai[3248:1575762] [DEBUG] -[LCCurlScheduler logCurlOperation:] [Line 80]

------ BEGIN LeanCloud REST Request ------
path: /1.1/batch/save
curl: curl -i -k --compressed -X POST -H 'User-Agent: AVOS Cloud iOS-v3.2.7 SDK' -H 'Content-Type: application/json; charset=utf-8' -H 'Accept: application/json' -H 'X-LC-Id: DAnhL7gnMRhoEifbTM4xII29-gzGzoHsz' -H 'X-LC-Sign: 54ca8134621bb7b3efba6e1c844daa8e,1459826349371' -H 'X-LC-Session: jo2vqbj6q6v6fck32w4npmra2' -H 'X-LC-Prod: 1' -d '{"requests":[{"path":"\/1.1\/classes\/Note","body":{"responsible":{"type":"Pointer","className":"_User","objectId":"56f253b28ac2470054ccb350"},"internalId":"5Rcw3UPCXsTQoD27rm8tD4D","pic_urls":[],"type":1,"text":"这是什么事也有很多事情"},"method":"POST","new":true}]}' "https://api.leancloud.cn/1.1/batch/save"
------ END -------------------------------

2016-04-05 11:19:11.019 RunTai[3248:1575766] [DEBUG] _56-[AVPaasClient performCurl:saveResult:block:retryTimes:]block_invoke [Line 614]

------ BEGIN LeanCloud REST Response ------
path: /1.1/batch/save
cost: 1.646s
response: {"5Rcw3UPCXsTQoD27rm8tD4D":{"objectId":"57032eaeebcb7d005b14de0e","createdAt":"2016-04-05T03:19:10.753Z"}}
------ END --------------------------------

2016-04-05 11:19:11.049 RunTai[3248:1575289] [DEBUG] -[LCCurlScheduler logCurlOperation:] [Line 80]

------ BEGIN LeanCloud REST Request ------
path: /1.1/classes/Project/56f4bc03da2f60004c4be4b0
curl: curl -i -k --compressed -X GET -H 'User-Agent: AVOS Cloud iOS-v3.2.7 SDK' -H 'Content-Type: application/json; charset=utf-8' -H 'Accept: application/json' -H 'X-LC-Id: DAnhL7gnMRhoEifbTM4xII29-gzGzoHsz' -H 'X-LC-Sign: b5d81195a608110deda19bc006ed8c4b,1459826351049' -H 'X-LC-Session: jo2vqbj6q6v6fck32w4npmra2' -H 'X-LC-Prod: 1' "https://api.leancloud.cn/1.1/classes/Project/56f4bc03da2f60004c4be4b0"
------ END -------------------------------

2016-04-05 11:19:11.050 RunTai[3248:1575289] [INFO] +[AVUtils warnMainThreadIfNecessary] [Line 202] Warning: A long-running Paas operation is being executed on the main thread.
2016-04-05 11:19:11.541 RunTai[3248:1575762] [DEBUG] _56-[AVPaasClient performCurl:saveResult:block:retryTimes:]block_invoke [Line 614]

------ BEGIN LeanCloud REST Response ------
path: /1.1/classes/Project/56f4bc03da2f60004c4be4b0
cost: 0.492s
response: {"updatedAt":"2016-04-03T13:55:23.468Z","processing":6,"watch_count":1128,"name":"14.3\u4e07\/98\u33a1\/\u4e09\u5c45\/\u73b0\u4ee3 \u65b0\u53e4\u5178","objectId":"56f4bc03da2f60004c4be4b0","background":{"updatedAt":"2016-03-25T06:20:44.954Z","key":"bd1c60594fb00011.jpg","name":"\u5510\u4e30\u82d1 2\u53f71102 \u9910\u5385 \u9152\u67dc.jpg","objectId":"56f4d8bc8ac247004d10ef5d","createdAt":"2016-03-25T06:20:44.954Z","type":"File","url":"http:\/\/ac-DAnhL7gn.clouddn.com\/bd1c60594fb00011.jpg","metaData":{"size":1381909,"owner":"unknown"},"bucket":"DAnhL7gn"},"createdAt":"2016-03-25T04:18:11.319Z","responsible":{"type":"Pointer","className":"User","objectId":"56fddba7d342d3005cbe70cb"},"notes":null,"fullname":"[\u5e7f\u4e1c \u73e0\u6d77 \u4e1c\u5cb8\u6751]","owner":{"_type":"Pointer","className":"User","objectId":"56f253b28ac2470054ccb350"}}
------ END --------------------------------

2016-04-05 11:19:11.559 RunTai[3248:1575289] -[NSNull mutableCopyWithZone:]: unrecognized selector sent to instance 0x1a16b2ea8
(lldb)

2016-04-05 11:25:03.202 RunTai[3248:1575289] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull mutableCopyWithZone:]: unrecognized selector sent to instance 0x1a16b2ea8'
*** First throw call stack:
(0x1857ecf48 0x19a39ff80 0x1857f3c5c 0x1857f0c00 0x1856f4cac 0x100207034 0x100207344 0x100207550 0x1001b0600 0x100a95ca8 0x100a95c68 0x100a9b710 0x1857a41f8 0x1857a2060 0x1856d0ca0 0x19090c088 0x18ade8ffc 0x10017b3ec 0x19abee8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException

你好,日志中的 request 和 response 都正常返回了信息,看错误堆栈中也并没有 LeanCloud 相关的代码。建议打一下断点,看看报错具体出现在哪一行代码中。

报错的具体位置就是这啊

请上传一个可复现问题的 Demo。

BugForAddObjectDemo 2.zip2 (42.8 KB)

AVOSCloud的库有27M,太大了,我上传不了,所以我没有把它打入zip包,你解压后要手动把库加进去噢

我想问一下,有没有在帮我处理这个问题呢?至少给个回复我吧。

正在定位问题,请稍后

你好,我们发现你的 Array 字段内容是 Null,请问你的 Null 是怎么加进去的?

我给你的demo你应该看的到addobject的字段是个avobject啊,而且断点是可以看到note字段并不是nil。我尝试过直接通过objectid来获取note,然后再addobject,但是一样是不可以的。所以为什么会是null,我更想知道啊……

大概明白你的意思,我试试看