0

だから私のコードは言う

no visible @interface for UIImagePicker Controller

Tab View Controller を使用しています 私の FirstViewController.m のコードは

#import "FirstViewController.h"
@interface FirstViewController () <UIImagePickerControllerDelegate, UINavigationControllerDelegate> {
UIImagePickerController *bailey;
UIImagePickerController *baileys;
UIImage *image;
IBOutlet UIImageView *imageView;
}
-  (IBAction)takePhoto;
-  (IBAction)chooseExisting;
@end
@implementation FirstViewController
 - (IBAction)takePhoto {
bailey = [[UIImagePickerController alloc]init];
bailey.delegate = self;
[bailey setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:bailey animated:YES completion:NULL];
}
- (IBAction)chooseExisting {
baileys = [[UIImagePickerController alloc] init];
baileys.delegate = self;
[baileys setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:baileys animated:YES completion:NULL];
}
- (void) imagePickerController:(UIImagePickerController *)picker                 didFinishPickingMediaWithInfo:(NSDictionary *)info {
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[imageView setImage:image];
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)bailey {
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (IBAction)ShareFB {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
    slComposeViewController = [SLComposeViewController     composeViewControllerForServiceType:SLServiceTypeFacebook];
    [slComposeViewController addImage:[UIImage imageNamed:@"image"]];
    [slComposeViewController addURL:[NSURL URLWithString:@"http://www.agfg.com.au"]];
    [self presentViewController:slComposeViewController animated:YES completion:NULL];
    //I borrowed these lines of code from http://www.bit.ly/174eqjy
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *appFile = [documentsDirectory stringByAppendingString:@"upload.png"];
    NSString *upLoad = [documentsDirectory stringByAppendingString:@"upload.png"];
    NSData *myData = [[NSData alloc]initWithContentsOfFile:appFile];
    //Here is the line that fails
    [bailey addAttachmentData:myData mimeType:@"image/png" fileName:@"upload"];
    //Up to here are the borrowed code lines.
    }
    else {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Facebook Account     Detected" message:@"There are no Facebook Accounts Detected. You can configure them in Settings." delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [alert show];

    }}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end

私のFirstViewController.hのコードは

#import <UIKit/UIKit.h>
#import <Social/Social.h>
 @interface FirstViewController : UIViewController {SLComposeViewController    *slComposeViewController;
UIImage *upLoad;}
- (IBAction)ShareFB;
@end

私のアプリは、写真を撮って写真を表示するように設計されており(そしてそれを行います)、その画像をアプリのローカルドキュメントフォルダーに保存し(別の投稿から取得しました)、その画像を指定してFacebookにアップロードします(これは私は持っている)

ローカルドキュメントへの保存を除いて、すべて機能します。

4

2 に答える 2

0

ドキュメント ディレクトリにファイルを保存する必要がある場合は、次のように使用します。

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"Images"];

if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
{
            [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:nil];
}

NSString *imageFilePath = [NSString stringWithFormat:@"%@/%@",dataPath,@"upload.png"];

UIImage *image = [UIImage imageNamed:@"image"]; //Here place your image
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
[imageData writeToFile:imageFilePath atomically:YES];

Facebook に画像を添付する必要がある場合は、次のステートメントを使用します。

[slComposeViewController
 addAttachmentData:UIImagePNGRepresentation(image, 1) mimeType:@"image/png" fileName:@"upload.png"];
于 2013-10-03T06:50:25.677 に答える
0

Karthika と彼の facebook アップロード コードの助けを借りて、ローカル ドキュメント保存を実装する必要がないことに気付いたとき、私はそれを入力していました。

Facebook では、画像を保存せずに追加できます。

Karthika に感謝します。あなたなしではできなかったでしょう。

于 2013-10-04T11:17:45.727 に答える