首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >终止应用程序- NSInvalidArgumentException

终止应用程序- NSInvalidArgumentException
EN

Stack Overflow用户
提问于 2015-04-25 06:35:07
回答 1查看 53关注 0票数 0

运行Anypic代码时崩溃。

代码语言:javascript
运行
复制
-(void)sendCommentButton:(id) sender {
        NSString *trimmedComment = [commentTextView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
        if (trimmedComment.length != 0 && [self.photo objectForKey:kPAPPhotoUserKey]) {
            PFObject *comment = [PFObject objectWithClassName:kPAPActivityClassKey];
            [comment setObject:trimmedComment forKey:kPAPActivityContentKey]; // Set comment text
            [comment setObject:[self.photo objectForKey:kPAPPhotoUserKey] forKey:kPAPActivityToUserKey]; // Set toUser
            [comment setObject:[PFUser currentUser] forKey:kPAPActivityFromUserKey]; // Set fromUser
            [comment setObject:kPAPActivityTypeComment forKey:kPAPActivityTypeKey];
            [comment setObject:self.photo forKey:kPAPActivityPhotoKey];
            [comment setObject:self.photoFile forKey:@"attachmentFile"];


            PFACL *ACL = [PFACL ACLWithUser:[PFUser currentUser]];
            [ACL setPublicReadAccess:YES];
            [ACL setWriteAccess:YES forUser:[self.photo objectForKey:kPAPPhotoUserKey]];
            comment.ACL = ACL;

            [[PAPCache sharedCache] incrementCommentCountForPhoto:self.photo];

            // Show HUD view
            [MBProgressHUD showHUDAddedTo:self.view.superview animated:YES];

            // If more than 5 seconds pass since we post a comment, stop waiting for the server to respond
            NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:5.0f target:self selector:@selector(handleCommentTimeout:) userInfo:@{@"comment": comment} repeats:NO];

            [comment saveEventually:^(BOOL succeeded, NSError *error) {
                [timer invalidate];

                if (error && error.code == kPFErrorObjectNotFound) {
                    [[PAPCache sharedCache] decrementCommentCountForPhoto:self.photo];
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Could not post comment", nil) message:NSLocalizedString(@"This photo is no longer available", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
                    [alert show];
                    [self.navigationController popViewControllerAnimated:YES];
                }

                [[NSNotificationCenter defaultCenter] postNotificationName:PAPPhotoDetailsViewControllerUserCommentedOnPhotoNotification object:self.photo userInfo:@{@"comments": @(self.objects.count + 1)}];

                [MBProgressHUD hideHUDForView:self.view.superview animated:YES];
                [self loadObjects];
            }];

        }

        [self.commentTextView setText:@""];
        [self.commentTextView resignFirstResponder];
        if (self.photoFile != nil) {
            self.photoFile = nil;
        }


}

选择图像

代码语言:javascript
运行
复制
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    NSLog(@"Hello");
    UIImage *img = [info objectForKey:UIImagePickerControllerOriginalImage];


    // JPEG to decrease file size and enable faster uploads & downloads
    NSData *imageData = UIImageJPEGRepresentation(img, 0.8f);

    self.photoFile = [PFFile fileWithData:imageData];

    // Request a background execution task to allow us to finish uploading the photo even if the app is backgrounded
    self.fileUploadBackgroundTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        [[UIApplication sharedApplication] endBackgroundTask:self.fileUploadBackgroundTaskId];
    }];

    NSLog(@"Requested background expiration task with id %lu for Anypic photo upload", (unsigned long)self.fileUploadBackgroundTaskId);
    [self.photoFile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            NSLog(@"Photo uploaded successfully");
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Photo Uploaded"
                                                            message:@"successfully"
                                                           delegate:self
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
            [alert show];
        } else {

            [[UIApplication sharedApplication] endBackgroundTask:self.fileUploadBackgroundTaskId];

        }
    }];

    [self dismissViewControllerAnimated:YES completion:nil];
}

问题:为什么要崩溃?我相信这就是破解它的密码。我做了什么崩溃,它不是添加一个attachmentFile,只是发表评论。

如果您需要更多代码或需要任何澄清,请在下面进行注释

EN

回答 1

Stack Overflow用户

发布于 2015-04-25 06:38:44

代码语言:javascript
运行
复制
PFObject *comment = [PFObject objectWithClassName:kPAPActivityClassKey];
[comment setObject:trimmedComment forKey:kPAPActivityContentKey]; // Set comment text
[comment setObject:[self.photo objectForKey:kPAPPhotoUserKey] forKey:kPAPActivityToUserKey]; // Set toUser
[comment setObject:[PFUser currentUser] forKey:kPAPActivityFromUserKey]; // Set fromUser
[comment setObject:kPAPActivityTypeComment forKey:kPAPActivityTypeKey];
[comment setObject:self.photo forKey:kPAPActivityPhotoKey];
[comment setObject:self.photoFile forKey:@"attachmentFile"];

在其中一行中,您将向setObject:forKey的第一个参数传递nil。添加一个异常断点(在左侧侧栏的“断点”选项卡中),并检查它在哪一行上断开。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29861876

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档