Tag: 编码

检查NSString是否被编码

如何检测已经编码的NSString 。 我正在编码我的string,如下所示。 编码之前,我只是想validation天气这[product url]已经编码或不。 NSString *encodedUrlString=[[product url] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

带有元音变音的iOS HttpRequest的长度不正确

在iOS中,我正在构build一个http请求,如下所示: NSURL* url = [ NSURL URLWithString:[ NSString stringWithFormat: @"%@%@", [ HPSWebService getBaseURL ], @"Sync/PushObject"] ]; // 'request' is defined within the base class and is set here to the class-specific server url request = [[NSMutableURLRequest alloc] initWithURL:url]; NSString* jsonRequest = [NSString stringWithFormat: @"{\"collection\":\"responses\",\"id\":\"%@\",\"objectjson\":%@}",response.id,response.json]; NSLog(@"HPSPushResponsesWebService jsonRequest = %@",jsonRequest); NSData *requestData = [NSData dataWithBytes:[jsonRequest UTF8String] length:[jsonRequest […]

无法在URL + swift中对Plus字符进行编码

我正在使用GET方法,我必须在URL中传递电子邮件地址。 API期望它被编码。 我尝试了编码选项,但'+'字符不能被编码。 我试着用下面的代码 let encodedEmail = emailAddressTxt.text!.addingPercentEncoding(withAllowedCharacters:.urlHostAllowed) let urlString = "http://www.example.com/User/GetUserDetailsByEmailAddress?EmailAddress=\(encodedEmail!)" print(escapedString) 它打印http://www.example.com/User/GetUserDetailsByEmailAddress?EmailAddress=mano+1%40gmail.com “@”字符只编码,“+”不编码。

尝试将非属性列表对象设置为NSUserDefaults

我以为我知道是什么导致了这个错误,但我似乎无法弄清楚我做错了什么。 这是我得到的完整的错误消息: 尝试设置一个非属性列表对象( “<BC_Person:0x8f3c140>” )作为关键personDataArray的NSUserDefaults值 我有一个Person类,我认为是符合NSCoding协议,我在这个人类中有这两种方法: – (void)encodeWithCoder:(NSCoder *)coder { [coder encodeObject:self.personsName forKey:@"BCPersonsName"]; [coder encodeObject:self.personsBills forKey:@"BCPersonsBillsArray"]; } – (id)initWithCoder:(NSCoder *)coder { self = [super init]; if (self) { self.personsName = [coder decodeObjectForKey:@"BCPersonsName"]; self.personsBills = [coder decodeObjectForKey:@"BCPersonsBillsArray"]; } return self; } 在应用程序的某个时刻, BC_PersonClass的NSString被设置,并且我有一个DataSave类,我认为它正在处理BC_PersonClass的属性的编码。 这里是我从DataSave类使用的代码: – (void)savePersonArrayData:(BC_Person *)personObject { // NSLog(@"name of the person %@", personObject.personsName); [mutableDataArray […]

Swift存储和恢复button上的ViewController状态点击

我正在使用Xcode 8和Swift 2.3 我浏览了几个网站,这些网站是关于国家恢复方法的指南: State Restoration Tutorial: Getting Started https://github.com/shagedorn/StateRestorationDemo/blob/master/StateRestorationDemo/CityViewController.swift 但我需要存储和恢复视图控制器的状态button点击通过确定的关键。 我不能使用故事板中的单一标识符,因为我需要保存同一个viewcontroller的许多实例,所以需要为每个实例使用不同的标识符,基于传递的密钥标识符,它应该只恢复相同视图控制器的特定实例 func sevNameVccBtnFnc(identifierKey :String) { // How to manually call encodeRestorableStateWithCoder } func revNameVccBtnFnc(identifierKey :String)->nameVcc { // How to manually call decodeRestorableStateWithCoder } AppDelegate代码: func application(application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool { return true } func application(application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool […]

内存增加,同时从数据库中提取数据以加载图像

我正在将图像的数据存储到数据库中的应用程序 NSString *query = [NSString stringWithFormat:@"INSERT INTO Friends_user (f_id,f_name,f_image,f_mobile) VALUES('%ld','%@','%@','%@')",(long)id_, self.txt_name.text,[UIImagePNGRepresentation(self.img_userprofile.image) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength], self.txt_mobile_no.text ]; 它存储成功,但是当我检索数据显示图像时,内存随着每个图像增加。 这是我的代码来检索数据 NSData *data = [[NSData alloc]initWithBase64EncodedString:[[arr_friendList objectAtIndex:indexPath.row] objectAtIndex:2] options:NSDataBase64DecodingIgnoreUnknownCharacters]; img_friend_profile.image= [UIImage imageWithData:data]; [theAppDelegate.dbManager executeQuery:query]; 数据库中的我的数据types是BLOB。 内存提高每个图像10-20 MB。 请帮助我 谢谢

如何解决编码问题? (NSString / XMLParsing)

我parsing了一个包含UTF8 /拉丁字符(é,â,è,等等)的XML文件。 起初我试图用一个replace错误字符的函数来解决这个问题。 但是我遇到了一个问题,换成了“ 。因为我不想全部replace我的文件,我必须find另一种方法来解决这个问题。 任何想法解决这个问题? 非常感谢您的build议

核心数据错误: – :无法识别的select器发送到实例

我有一个自定义的类MyClass基本上由几个NSMutableArrays组成,没有其他variables。 我有一个实体MyEntity具有MyClass的伊娃。 当我尝试保存实体时,我得到这个堆栈转储: 0 CoreFoundation 0x0118ebe9 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x012e35c2 objc_exception_throw + 47 2 CoreFoundation 0x011906fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 3 CoreFoundation 0x01100366 ___forwarding___ + 966 4 CoreFoundation 0x010fff22 _CF_forwarding_prep_0 + 50 5 Foundation 0x00091bf6 _encodeObject + 1076 6 Foundation 0x0009d041 +[NSKeyedArchiver archivedDataWithRootObject:] + 206 7 CoreData 0x00eb7255 -[NSSQLiteConnection execute] + 2677 8 […]

iOS utf-8编码问题

我尝试使用UTF-8字符集获取HTML页面 NSString *html=[NSString stringWithContentsOfURL:[NSURL URLWithString: @"http://forums.drom.ru/general/t1151288178.html"] encoding:NSUTF8StringEncoding error:&error]); 但NSLog(@"%@",html)返回null为什么会发生这种情况?

带有Alamofire 4数据的POST请求

怎么可能用Alamofire 4发送POST请求与HTTP正文中的数据? 我使用自定义编码在迅速2.3它工作良好。 我转换我的代码swift 3,我试图参数编码,但不工作。 此代码: public struct MyCustomEncoding : ParameterEncoding { private let data: Data init(data: Data) { self.data = data } public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest { var urlRequest = try urlRequest.asURLRequest() do { urlRequest.httpBody = data urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type") } catch { throw AFError.parameterEncodingFailed(reason: .jsonEncodingFailed(error: error)) […]