应用程序崩溃例外: - [NSConcreteMutableData _fastCharacterContents] [英] App crashing with exception: -[NSConcreteMutableData _fastCharacterContents]

查看:1337
本文介绍了应用程序崩溃例外: - [NSConcreteMutableData _fastCharacterContents]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试与Facebook分享数据。我可以共享除本地存储在iPhone内存中的图像之外的数据。但是当我尝试使用参数@source分享存储在本地的图像时,我的应用程序会以[NSConcreteMutableData _fastCharacterContents]的错误终止。



根据@source参数的要求将其转换为NSData。

  NSData * data = [NSData dataWithContentsOfURL:localUrl]; 

__block ACAccount * facebookAccount = nil;

ACAccountType * facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

//指定应用程序ID和权限
NSDictionary * options = @ {
ACFacebookAppIdKey:@xxxxxxxxxxxxxx,

ACFacebookPermissionsKey:@ [@电子邮件],
ACFacebookAudienceKey:ACFacebookAudienceEveryone
}; //基本读取权限

[self.accountStore requestAccessToAccountsWithType:facebookAccountType
选项:选项完成:^(BOOL授予,NSError * e)
{
如果){
//现在你有发布权限执行请求
NSDictionary * options2 = @ {
ACFacebookAppIdKey:@xxxxxxxxxxxxxx,
ACFacebookPermissionsKey:@ [@publish_stream ,@publish_actions],
ACFacebookAudienceKey:ACFacebookAudienceFriends
};
[self.accountStore requestAccessToAccountsWithType:facebookAccountType选项:options2完成:^(BOOL授予,NSError *错误){
如果(被授予){
NSArray * accounts = [self.accountStore accountsWithAccountType:facebookAccountType ]。

facebookAccount = [accounts lastObject];

/ * NSDictionary * parameters = @ {@message:@这是一个测试,
@name:@共享教程,
@标题:@构建优秀的社交应用程序并获得更多的安装,
@description:@允许您的用户使用iOS SDK从您的应用程序在Facebook上分享故事,
@ link:@https://developers.facebook.com/docs/ios/share/,
@source:data}; * /
NSMutableDictionary * parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@我的帽子图像,@消息,数据,@源,nil];

NSURL * feedURL = [NSURL URLWithString:@https://graph.facebook.com/me/photos];

SLRequest * feedRequest = [SLRequest
requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:feedURL
参数:参数];
NSLog(@AnythingHere?);

[feedRequest setAccount:facebookAccount];

[feedRequest performRequestWithHandler:^(NSData * responseData,
NSHTTPURLResponse * urlResponse,NSError * error)
{
//处理响应
NSLog(@ %@%@,error,urlResponse);

NSDictionary * response = [NSJSONSerialization JSONObjectWithData:responseData选项:kNilOptions错误:nil];

NSLog(@Facebook Response:%@,response);

}];



}
else {
NSLog(@Access denied 2);
NSLog(@%@,[错误描述]);
}
}];
} else {
NSLog(@Error:%@,[e description]);
NSLog(@访问被拒绝);
}
}];

这个错误背后的原因是什么?

解决方案

这只是一个受过教育的猜测,因为我从未使用过社交框架,但评论太长了。



根据这个回答,我会说你正在使用 SLRequest 错误。我确定异常来自您的数据对象,它被解释为NSString(或NSURL)。

也许你应该使用 addMultipartData:withName:type:filename: 将您的照片附加到请求。

  NSMutableDictionary * parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@我的帽子图像,@message,nil] ;

NSURL * feedURL = [NSURL URLWithString:@https://graph.facebook.com/me/photos];

SLRequest * feedRequest = [SLRequest
requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:feedURL
参数:参数];

[feedRequest addMultipartData:data
withName:@source
type:@multipart / form-data
filename:@Test Image];

这些代码与另一个答案


I am trying to share data with facebook. I am able to share data except image stored locally in iPhone memory. But when I try to share image stored locally with parameter @"source" my app gets terminated with error "[NSConcreteMutableData _fastCharacterContents]".

For sharing a local image I am converting it into NSData as required by @"source" parameter.

NSData *data = [NSData dataWithContentsOfURL:localUrl];

   __block ACAccount *facebookAccount = nil;

    ACAccountType *facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

    // Specify App ID and permissions
    NSDictionary *options = @{
                              ACFacebookAppIdKey: @"xxxxxxxxxxxxxx",

                              ACFacebookPermissionsKey: @[@"email"],
                              ACFacebookAudienceKey: ACFacebookAudienceEveryone
                              }; // basic read permissions

    [self.accountStore requestAccessToAccountsWithType:facebookAccountType
                                          options:options completion:^(BOOL granted, NSError *e)
     {
         if (granted) {
             // Now that you have publish permissions execute the request
             NSDictionary *options2 = @{
                                        ACFacebookAppIdKey: @"xxxxxxxxxxxxxx",
                                        ACFacebookPermissionsKey: @[@"publish_stream", @"publish_actions"],
                                        ACFacebookAudienceKey: ACFacebookAudienceFriends
                                        };
             [self.accountStore requestAccessToAccountsWithType:facebookAccountType options:options2 completion:^(BOOL granted, NSError *error) {
                 if (granted) {
                     NSArray *accounts = [self.accountStore accountsWithAccountType:facebookAccountType];

                     facebookAccount = [accounts lastObject];

                     /*NSDictionary *parameters = @{@"message": @"This is a test",
                                                  @"name": @"Sharing Tutorial",
                                                  @"caption": @"Build great social apps and get more installs.",
                                                  @"description": @"Allow your users to share stories on Facebook from your app using the iOS SDK.",
                                                  @"link": @"https://developers.facebook.com/docs/ios/share/",
                                                  @"source":data};*/
                     NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                                    @"My hat image", @"message", data, @"source", nil];

                     NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/photos"];

                     SLRequest *feedRequest = [SLRequest
                                               requestForServiceType:SLServiceTypeFacebook
                                               requestMethod:SLRequestMethodPOST
                                               URL:feedURL
                                               parameters:parameters];
                     NSLog(@"AnythingHere?");

                     [feedRequest setAccount:facebookAccount];

                     [feedRequest performRequestWithHandler:^(NSData *responseData,
                                                              NSHTTPURLResponse *urlResponse, NSError *error)
                      {
                          // Handle response
                          NSLog(@"%@%@", error,urlResponse);

                          NSDictionary *response = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil];

                          NSLog(@"Facebook Response : %@",response);

                      }];



                 }
                 else {
                     NSLog(@"Access denied 2");
                     NSLog(@"%@", [error description]);
                 }
             }];
         } else {
             NSLog(@"Error: %@", [e description]);
             NSLog(@"Access denied");
         }
     }];

What can be the reason behind this error?

解决方案

This is just an educated guess because I've never used the Social framework, but it's too long for a comment.

Judging by this answer I would say that you are using SLRequest wrong. I'm pretty sure that the exception comes from your data object which is interpreted as a NSString (or NSURL).
Maybe you should use addMultipartData:withName:type:filename: to attach your photo to the request.

NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                      @"My hat image", @"message", nil];

NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/photos"];

SLRequest *feedRequest = [SLRequest
              requestForServiceType:SLServiceTypeFacebook
              requestMethod:SLRequestMethodPOST
              URL:feedURL
              parameters:parameters];

[feedRequest addMultipartData:data
                     withName:@"source"
                         type:@"multipart/form-data"
                     filename:@"Test Image"];

which is basically the same code as another answer

这篇关于应用程序崩溃例外: - [NSConcreteMutableData _fastCharacterContents]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆