0

任何人都可以告诉我如何在 iphone 中调用 megnto api 的登录方法我已经在安卓中使用 xmlrpc 库完成了它

// ...
String sessionId = "";
//HashMap<string , String> params = new HashMap</string><string , String>();
//params.put("apiUser", "developer");
//params.put("apiKey", "magento123");
XMLRPCClient client = new XMLRPCClient("http://some-site.com/index.php/api/xmlrpc/");
try {
    /*
        sessionId = (String)client.callEx("login", new Object[]{params});
        will cause
        DEBUG/MY_XMLRPCException_MSG(196): XMLRPC Fault: Calling parameters do not match signature 1
    */
    sessionId = (String)client.call("login", "developer", "magento123");
    Log.d("MY_XMLRPC_SUCCESS_SESSION_ID", sessionId);
}
catch (XMLRPCException e) {
    Log.d("MY_XMLRPCException_MSG", e.getMessage());
}

我是 iphone 的新手,我怎么能在 iphone 中做任何事情,任何人都可以告诉我,图书馆或例子让我做我想做的事!!!

4

1 回答 1

2

我得到了解决方案,我正在使用来自 git hub 的 AFNetworking 库,我正在使用以下链接中给出的库 https://github.com/lognllc/LogNMagento

一些基本步骤

=> 在您的应用程序中导入 LogNMangento 应用程序

=> 在 magento.h - (void)settingLogin:(completionBlock) completionBlock;

=> 在 magento.m 中

- (void)settingLogin:(completionBlock)completionBlock
{

standardUserDefaults = [NSUserDefaults standardUserDefaults];
array =[standardUserDefaults objectForKey:@"Prefs"];

client = [[MagentoClient alloc] initWithBaseURL:[NSURL URLWithString:[array objectAtIndex:0]]];
[client setDefaultHeader:@"SOAPAction" value:@"urn:Mage_Api_Model_Server_HandlerAction"];
[client registerHTTPOperationClass:[SoapRequestOperation class]];
[SoapRequestOperation addAcceptableStatusCodes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 301)]];
[client setDefaultHeader:@"Content-Type" value:@"text/xml; charset=utf-8"];
[client postPath:@"login" parameters:@{@"username":[array objectAtIndex:1], @"apiKey": [array objectAtIndex:2] }  success:^(AFHTTPRequestOperation *operation, id responseObject) {
    sessionID = responseObject;
    completionBlock(sessionID);
} failure:^(AFHTTPRequestOperation *operationData, NSError *error) {
    NSLog(@"Response is not get");
    sessionID = FAILED_SESSION;
    completionBlock(sessionID);
}];

}

=> 在你的课上叫这个

[Magento.service settingLogin:^(NSString *session) {
            if(session){

                NSLog(@"Session %@",session);
                if(![session isEqualToString:@"NULL"])
                {
                    [self.view hideToastActivity];


                  self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
                    [self.navigationController pushViewController:self.viewController animated:YES];
                }
                else
                {
                    [self.view hideToastActivity];
                    [self.view makeToast:@"Please Check Store Info"];
                    session=nil;
                }
            }
            else{

            }
        }];
    }
    else
    {
        [self.view makeToast:@"Please insert data"
                    duration:1.0
                    position:@"bottom"
                       ];
    }

是的,还可以在基本网址中对 magento.m 的 INIT 进行一些更改

于 2013-05-03T12:17:33.437 回答