今天扩展小部件 - 按钮操作调用Web服务

时间:2015-02-11 07:06:12

标签: ios iphone xcode6 ios8-today-widget

我是Today Extension Widget的新手 任何人都告诉我如何使用今天Extenstion小部件上的按钮调用Web服务? 我怎么称呼它?它是否使用用于从我的主应用程序调用webservice的类来调用即使应用程序处于关闭状态或最小化状态? 这就是我的小部件的期望。

|=========================================|
|                                         |
|  MY TODAY WIDGET API CALL               |
|          ----------------               |
|         |   CALL API     |              |
|          ----------------               |
|                                         |
|=========================================|

我必须在按下按钮时调用API,其中包含以下参数

1)的用户名 2)的userPassword 3)用户手机号码 4)用户纬度 5)用户经度 6)精度 7)式

-(void)CallApi
{
 NSString * devUrl = [NSString stringWithFormat:@"http://www.myhost.com/api/login?username=%@&password=%@&mobileno=%@,&latitude=%@&longitude=%@&accuracy=%@&type=%@",user_Name,password,mobile_Number,latitudeString,longitudeString,accuracyString,@"login"];
    connection *new_connection;
    new_connection = [[connection alloc] init];
    [new_connection setHttp_delegate:self];
    [new_connection make_request:devUrl];
}





#pragma mark -
#pragma mark http delegate

- (void) httpConnection:(connection *)connect didReciveresponse:(NSUInteger)errorCode
{
    NSLog(@"errorCode%i",errorCode);
}


- (void) httpConnection:(connection *)connect didFinishWithLoadingData:(NSData*)data
{
    [[UIApplication sharedApplication] endIgnoringInteractionEvents];
     NSString* responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    if([responseString rangeOfString:@"nil"].location != NSNotFound)
    {
        NSString * newResponse =  [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
        responseString = newResponse;
    }
    NSLog(@"%@",responseString);

}

0 个答案:

没有答案