GVKun编程网logo

ios – 如何在Objective-C中将ISO语言代码转换为其语言名称?(c语言如何把apple变成apple)

4

关于ios–如何在Objective-C中将ISO语言代码转换为其语言名称?和c语言如何把apple变成apple的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于ios–Instagram

关于ios – 如何在Objective-C中将ISO语言代码转换为其语言名称?c语言如何把apple变成apple的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于ios – Instagram – 如何在Objective C中使用API跟踪用户、ios – 如何在Objective c中使用AES Crypto发送CommonCrypto POST请求?、ios – 如何在Objective C中使用NSPredicate指定范围、iOS – 如何在Objective C中向kal库添加事件?等相关知识的信息别忘了在本站进行查找喔。

本文目录一览:

ios – 如何在Objective-C中将ISO语言代码转换为其语言名称?(c语言如何把apple变成apple)

ios – 如何在Objective-C中将ISO语言代码转换为其语言名称?(c语言如何把apple变成apple)

参见英文答案 > Parsing ISO-639 language codes to show full English language names4个
我在iOS应用程序中从API获取ISO语言代码.例如,en表示英语,hi表示印地语等.我想将这些ISO代码转换为各自的语言名称.

这是由API返回的:

"category": "TVCHANEL","chanellanguage": "ar",

我怎样才能做到这一点?我是否必须创建一个带有ISO代码的字典作为每种语言的关键字?

解决方法

您可以使用NSLocale.请参考以下示例
NSLocale *locale = [NSLocale localeWithLocaleIdentifier:@"ar"];
NSLog(@"%@",[locale displayNameForKey:NSLocaleIdentifier value:@"ar"]);
Output: العربية

NSLocale *locale = [NSLocale localeWithLocaleIdentifier:@"en"];
NSLog(@"%@",[locale displayNameForKey:NSLocaleIdentifier value:@"ar"]);
Output: arabic

我希望这是你所需要的.

ios – Instagram – 如何在Objective C中使用API跟踪用户

ios – Instagram – 如何在Objective C中使用API跟踪用户

我会在我的应用程序的帮助下关注任何用户.谁能建议我做什么?当我从 here阅读Instagram API时.但是没有正确的想法该怎么做.

解决方法

你可以这样做: –

Nsstring *urlString=[Nsstring stringWithFormat:@"https://api.instagram.com/v1/users/%@/relationship?access_token=%@",<user id>,<access token>];

    NSURL* url = [NSURL URLWithString:urlString];
    theRequest = [NSMutableuRLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:1000.0];
    Nsstring *parameters=@"action=follow";
    [theRequest setHTTPBody:[parameters dataUsingEncoding:NSUTF8StringEncoding]];
    [theRequest setHTTPMethod:@"POST"];

ios – 如何在Objective c中使用AES Crypto发送CommonCrypto POST请求?

ios – 如何在Objective c中使用AES Crypto发送CommonCrypto POST请求?

我只是尝试从iOS应用程序向目标c中的PHP平台Web服务发送安全请求.我尝试了2天,但我没有找到逻辑或任何如何实现这一点:

以下是使用CryptoSwift Framework的Swift代码

func HTTPPostJSON(url: String,jsonData: Dictionary<String,AnyObject>,type: String = "POST",encrypt: Bool = false,callback: (String,String?) -> Void) {
        if Debug().state {
            print("** Start HTTP")
        }
        crypto_enabled = encrypt
        let req = NSMutableuRLRequest(URL: NSURL(string: url)!)
        req.HTTPMethod = type
        req.addValue(self.dataType,forHTTPHeaderField: self.headerType)
        let json: JSON = JSON(jsonData)
        //        var data: NSData = NSJSONSerialization.dataWithJSONObject(json.object,options: nil,error: nil)!
        var data: NSData = NSData()
        do {
            data = try NSJSONSerialization.dataWithJSONObject(json.object,options: NSJSONWritingOptions.init(rawValue: 0))
        } catch {
            print("JSON to NSData error: \(error)")
        }
        if Debug().state {
            print("JSON Object: \(json)")
        }
        if crypto_enabled {
            if Debug().state {
                print("Encryption enabled")
            }
            let iv = Cipher.randomIV(AES.blockSize)
            //            println("UInt8 IV: \(iv)")
            let iv_size = iv.count //count(iv)
            print("IV Size: \(iv_size)")
            var key = [UInt8] (self.secret.utf8)
            //            println("UInt8 Key: \(key)")
            let secret_len = self.secret.characters.count
            print("Key length: \(secret_len)")

            if self.secret.characters.count != 32 {
                if Debug().state {
                    print("Hashing Secret")
                }
                let data: NSData = self.secret.dataUsingEncoding(NSUTF8StringEncoding,allowLossyConversion: false)!
                //                key = (CryptoSwift.Hash.md5(data).calculate()!).arrayOfBytes()
                key = (CryptoSwift.Hash.sha256(data).calculate()!).arrayOfBytes()
                if Debug().state {
                    print("New UInt8 Key: \(key)")
                    let new_key_len = key.count
                    print("New Key Length: \(new_key_len)")
                }
            }

            let aes = AES(key: key,iv: iv,blockMode: .CBC)!
            var encrypted: [UInt8] = []
            do {
                encrypted = try aes.encrypt(data.arrayOfBytes())
            } catch {
                print("Encrypt data Failed: \(error)")
            }
            // IV
            let ivData: NSData = NSData.withBytes(iv)
            //            println("IV in NSData: \(ivData)\n")
            let ivBase64 = ivData.base64EncodedDataWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
            //            println("IV in Base64: \(ivBase64)\n")
            let ivBase64String = Nsstring(data: ivBase64,encoding: NSUTF8StringEncoding) as! String
            //            println("IV in Base64 String: \(ivBase64String)\n")
            // cData
            let cData_Data = NSData.withBytes(encrypted)
            // 1st cData Base64 encoding
            let cData_Base64 = cData_Data.base64EncodedDataWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
            let cData_Base64String = Nsstring(data: cData_Base64,encoding: NSUTF8StringEncoding) as! String
            // 2nd cData Base64 encoding
            let cData_Base64String_Data = cData_Base64String.dataUsingEncoding(NSUTF8StringEncoding,allowLossyConversion: false)!
            let cData_L2_Base64 = cData_Base64String_Data.base64EncodedDataWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
            let cData_L2_Base64String = Nsstring(data: cData_L2_Base64,encoding: NSUTF8StringEncoding) as! String

            let cipheredDict: Dictionary<String,AnyObject> = [
                "iv": ivBase64String,"cData": cData_L2_Base64String // cData_Base64String
            ]
            var cipheredJSON: JSON = JSON(cipheredDict)
            //            let cipheredData: NSData = NSJSONSerialization.dataWithJSONObject(cipheredJSON.object,error: nil)!
            var cipheredData: NSData = NSData()
            do {
                cipheredData = try NSJSONSerialization.dataWithJSONObject(cipheredJSON.object,options: NSJSONWritingOptions.init(rawValue: 0))
            } catch {
                print("Ciphered JSON to NSData error: \(error)")
            }
            //            if Debug().state {
            //                println("Ciphered Data: \(cipheredData)")
            //            }
            data = cipheredData
        }
        //let jsonString = json //self.JSONStringify(json)
        //let data: NSData = jsonString.dataUsingEncoding(NSUTF8StringEncoding,allowLossyConversion: false)!
        req.HTTPBody = data
        self.HTTPSendReq(req,callback: callback)
    }

我尝试使用MIHCrypto在目标c中实现

NSMutableuRLRequest *request = [NSMutableuRLRequest requestWithURL:[NSURL URLWithString:@"http://00.00.00.000/member/slogin"]];


    NSMutableDictionary *parameters = [NSMutableDictionary new];
    [parameters setobject:@"POS" forKey:@"from"];
    [parameters setobject:@"52001" forKey:@"username"];
    [parameters setobject:@"111111" forKey:@"password"];

    // Specify that it will be a POST request
    request.HTTPMethod = @"POST";

    // This is how we set header fields
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
     NSError *jsonSerializationError = nil;

    Nsstring*secrate = @"keythatuser";



    // Convert your data and set your request's HTTPBody property
  NSData *jsonData = [NSJSONSerialization dataWithJSONObject:parameters options:NSJSONWritingPrettyPrinted error:&jsonSerializationError];



    NSError *error;
    NSData *encryptedData = [RNEncryptor encryptData:jsonData
                                        withSettings:kRNCryptorAES256Settings
                                            password:secrate
                                               error:&error];



    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];

    [conn start];

坦率地说,我不知道如何解析它,请指导我加密PHP服务器请求和解密后的加密响应.

解决方法

我们可以通过在Objective-C项目中创建一个Swift辅助类来实现.

使用安装pod在您的项目中

platform :ios,'8.0'
use_frameworks!

target 'CryptoTest' do
    pod 'CryptoSwift'
end

添加带有桥接头的帮助器swift文件

为此,请转到设置>包装>定义Module = True

现在在Helper文件中导入CryptoSwift

例如 :

//
//  CryptoHelper.swift
//  CryptoTest

import UIKit
import CryptoSwift

class CryptoHelper: NSObject {
    func crypttest(){
        /* Hash enum usage */
        let input:[UInt8] = [49,50,51]

        let output = input.md5()
        // alternatively: let output = CryptoSwift.Hash.md5(input).calculate()

        print(output.toHexString())
    }
}

现在在任何Objective-C(.m)文件中使用该帮助文件

例如:

#import "ViewController.h"
#import "CryptoTest-Swift.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    CryptoHelper *testCrypt = [[CryptoHelper alloc]init];
    [testCrypt cryptTest];
    // 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

这里#import“CryptoTest-Swift.h”表示#import“YourProjectModuleName-Swift.h”.

希望它能帮到你.

ios – 如何在Objective C中使用NSPredicate指定范围

ios – 如何在Objective C中使用NSPredicate指定范围

我想通过指定范围来查询sqllite表.所以这就像给我所有id列在3000到3010之间的记录.

我尝试了Apple推荐的产品,但它没有用.这是我尝试过但失败了.

nspredicate *betweenPredicate =
[nspredicate predicateWithFormat: @"attributeName BETWEEN %@",@[@1,@10]];

我有两个名为start和end的字符串.我更新了Apple的示例如下.

nspredicate *betweenPredicate =
[nspredicate predicateWithFormat: @"%@ BETWEEN %@",columnName,@[start,end]];

当我使用上面的谓词执行executeRequest时,我得到0条记录,即使该表具有与谓词匹配的记录.有人能说出错的地方吗?

解决方法

您必须为属性名称使用%K格式说明符:

[nspredicate predicateWithFormat: @"%K BETWEEN %@",end]];

如果这不起作用(我从来没有使用“BETWEEN”用于核心数据获取请求),那么
可以用等效的谓词代替它

[nspredicate predicateWithFormat: @"%K >= %@ AND %K <= %@",start,end];

iOS – 如何在Objective C中向kal库添加事件?

iOS – 如何在Objective C中向kal库添加事件?

我在项目需要日历视图中处理事件,我尝试了很多库,但最后我决定使用 kal library作为其添加事件的能力

Calendar.h

#import "Kal.h"
#import "NSDate+Convenience.h"
#import "EventKitDataSource.h"


@interface Calendar : UIViewController<WebService_Delegate,UITableViewDelegate >
{


    KalViewController *kal;
    id dataSource;
}

Calendar.m

- (void)viewDidLoad
{
    [super viewDidLoad];



    self.title = @"Caledar";
    kal = [[KalViewController alloc]initWithSelectionMode:KalSelectionModeSingle];
    kal.selectedDate = [NSDate dateStartOfDay:[NSDate date]];
     kal.delegate = self;


    kal.view.frame = CGRectMake(0,65,kal.view.frame.size.width,kal.view.frame.size.height);

    [kal showAndSelectDate:[NSDate date]];
    //navController = [[UINavigationController alloc]initWithRootViewController:kal];
   // [self.view addSubview:navController.view];
    [self initvariable];
    [self getEvents];


    dataSource = [[EventKitDataSource alloc] init];
    kal.dataSource = dataSource;



   [self.view addSubview:kal.view];

}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    // display a details screen for the selected event/row.
    EKEventViewController *vc = [[EKEventViewController alloc] init];

    vc.event = [dataSource eventAtIndexPath:indexPath];

    //[vc setEvent:[events_array objectAtIndex:indexPath.row]];
    vc.allowsEditing = NO;
    [navController pushViewController:vc animated:YES];
}

如何将数据传递给dataSource以显示它

这里看起来如何

我需要将事件列表设置到我的事件列表中,我将事件重复,从我的日历中读取

谢谢

解决方法

您需要在对象中实现KalDataSource协议,并将该对象设置为kal对象的数据源.该协议可在此处找到 https://github.com/klazuka/Kal/blob/master/src/KalDataSource.h

将KalDataSource协议添加到头文件中
< WebService_Delegate,UITableViewDelegate,KalDataSource>

在Calendar对象集的init方法中
kal.datasource = self

在对象中实现KalDataSource方法

今天关于ios – 如何在Objective-C中将ISO语言代码转换为其语言名称?c语言如何把apple变成apple的介绍到此结束,谢谢您的阅读,有关ios – Instagram – 如何在Objective C中使用API跟踪用户、ios – 如何在Objective c中使用AES Crypto发送CommonCrypto POST请求?、ios – 如何在Objective C中使用NSPredicate指定范围、iOS – 如何在Objective C中向kal库添加事件?等更多相关知识的信息可以在本站进行查询。

本文标签: