简体   繁体   中英

Why does SLRequest to get Twitter followers crash on iOS 6.1 but not 7.1

I tried to load a list of the user's Twitter followers. It loads fine on iOS 7.1, but crashes on iOS 6.1. The line that crashes is performRequestWithHandler: and the error is -[__NSCFNumber length]: unrecognized selector sent to instance 0xcb4d580 . What is the cause of the problem?

SLRequest* request = [SLRequest
    requestForServiceType:SLServiceTypeTwitter
    requestMethod:TWRequestMethodGET
    URL:[NSURL URLWithString:[NSString stringWithFormat:
        @"%@followers/list.json",
        API_BASE_URL
    ]]
    parameters:@{
        @"user_id": @(self.context.userId.integerValue),
        @"count": @(128),
        @"skip_status": @"true"
    }
];
request.account = self.context.account;
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
    // code that is irrelevant to crash
}];

These are how the above variables are defined:

  • API_BASE_URL is a static NSString @" https://api.twitter.com/1.1/ "
  • self.context.userId is an NSString of a number.
  • self.context.account is the ACAccount of the logged in user.

Given the error message it seems under iOS 6 you must be sure all request parameters are strings. Change your code for the parameters to something like:

parameters:@{
    @"user_id": self.context.userId,
    @"count": @"128",
    @"skip_status": @"true"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM