ios - 使用 Parse.com 上传视频

标签 ios parse-platform

我是解析新手,正在尝试保存视频并将其上传到云端。这是我正在使用的代码,但是在调用 doneButtonAction 时它一直出错。我认为问题出在将视频保存为文件时,但我不知道如何解决。提前谢谢你-

- (void)imagePickerController:(UIImagePickerController *)picker      didFinishPickingMediaWithInfo:(NSDictionary *)info {

    NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
    NSLog(@"%@", videoURL);


    if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (self.moviePath))
    {
        UISaveVideoAtPathToSavedPhotosAlbum (self.moviePath, nil, nil, nil);
    }

    [self shouldUploadVideo];
    [self doneButtonAction];
}

- (void)shouldUploadVideo {

    //Capturamos el NSUserdefault para grabar el evento
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *loadstring = [defaults objectForKey:@"Video"];
    NSLog(@"Working at first line");



    NSData *videoData = [NSData dataWithContentsOfURL:self.videoURL];
    NSLog(@"Working at second line");


    PFFile *videoFile = [PFFile fileWithData:videoData];
    NSLog(@"Working at third line");

    [self.videoFile saveInBackground];
    NSLog(@"Working at last line");

}

- (void)doneButtonAction {
    // Make sure there was no errors creating the image files
    if (!self.videoFile) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Couldn't save your photo"
                                                       message:nil
                                                       delegate:nil
                                              cancelButtonTitle:nil
                                              otherButtonTitles:@"Dismiss",nil];
        [alert show];
        return;
    }

    // Create a Photo object
    PFObject *video = [PFObject objectWithClassName:kPAPPhotoClassKey];
    [video setObject:[PFUser currentUser] forKey:kPAPPhotoUserKey];
    [video setObject:self.videoFile forKey:@"Video"];

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

    // Save the Photo PFObject
    [video saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            NSLog(@"Photo uploaded");

            // Add the photo to the local cache
            [[PAPCache sharedCache] setAttributesForPhoto:video likers:[NSArray array] commenters:[NSArray array] likedByCurrentUser:NO];

            // Send a notification. The main timeline will refresh itself when caught
            [[NSNotificationCenter defaultCenter] postNotificationName:PAPTabBarControllerDidFinishEditingPhotoNotification object:video];
        } else {
            NSLog(@"Photo failed to save: %@", error);
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Couldn't post your photo"
                                                            message:nil
                                                           delegate:nil
                                                  cancelButtonTitle:nil
                                                  otherButtonTitles:@"Dismiss",nil];
            [alert show];
        }

        // If we are currently in the background, suspend the app, otherwise
        // cancel request for background processing.
        [[UIApplication sharedApplication] endBackgroundTask:self.photoPostBackgroundTaskId];
    }];

    // Dismiss this screen
    [self.parentViewController dismissViewControllerAnimated:YES completion:nil];

}

最佳答案

内部

- (void)shouldUploadVideo {

你有:

PFFile *videoFile = [PFFile fileWithData:videoData];
NSLog(@"Working at third line");

[self.videoFile saveInBackground];
NSLog(@"Working at last line");

您正在尝试在后台上传 self.videoFile - 而不是 videoFile

这意味着 videoFile 没有在后台上传 PFFile。

改变

PFFile *videoFile = [PFFile fileWithData:videoData];

self.videoFile = [PFFile fileWithData:videoData];

关于ios - 使用 Parse.com 上传视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19072988/

相关文章:

ios - “在使用Parse之前,必须在registerSubclass中注册PFUser类。”

ios - iTunes Connect - 无法为预发布应用邀请 "internal testers"

ios - 使用 AVFoundation 终止应用程序错误的自定义相机 - SWIFT 4

dictionary - 在云代码中创建以 ParseObject 作为键的字典仅给出 [Object object]

ios - 在查询解析表之前获取位置查询

ios - 恢复应用内购买(使用 Parse)

ios - 根据字符串属性按字母顺序对对象数组进行排序

ios - 如何在 iOS 中以编程方式更新 UILabel

ios - 委托(delegate)内的 Obj-C 委托(delegate)

ios - Swift - 填充表行