Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

iOS mobil uygulamanızda, kişiye özel ürün önerileri göstermeniz için gerekli dokümanları bu bölümde bulabilirsiniz.


iOS – In App

Bir VisilabsTargetRequest nesnesi oluşturun:

Objective-C

VisilabsTargetRequest *request=[[Visilabs callAPI] buildTargetRequest: @"ZoneID" withProductCode: @"ProductCode"];

Swift

let targetRequest = Visilabs.callAPI().buildTargetRequest("ZoneID", withProductCode: "ProductCode")

Ayrıca, filtreleri ve ek parametreleri geçirebileceğiniz bir overload buildTargetRequest yöntemi bulunmaktadır:

Objective-C

NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
NSMutableArray *filters = [[NSMutableArray alloc] init];
[dic setObject:@"Extra Value" forKey:@"OM.extra"];
VisilabsTargetFilter *filter1 = [[VisilabsTargetFilter alloc] init];
filter1.attribute = @"attr1";
filter1.value =  @"val";
filter1.filterType =  @"1"; // There are 2 filter types: Include and Exclude. For Include pass "0", for Exclude pass "1".
[filters addObject:filter1];
VisilabsTargetFilter *filter2 = [[VisilabsTargetFilter alloc] init];
filter2.attribute = @"attr2";
filter2.value =  @"val";
filter2.filterType =  @"0"; // There are 2 filter types: Include and Exclude. For Include pass "0", for Exclude pass "1".
[filters addObject:filter2];


VisilabsTargetRequest *request=[[Visilabs callAPI] buildTargetRequest: @"ZoneID" withProductCode: @"ProductCode"  withProperties:dic withFilters:filters];


Swift

let zoneID = "9"
let dic = NSMutableDictionary()
dic["OM.extra"] = "Extra Value";
let filters = NSMutableArray()
let filter1 = VisilabsTargetFilter()
filter1.attribute = "attr1"
filter1.filterType = "1"// There are 2 filter types: Include and Exclude. For Include pass "0", for Exclude pass "1".
filter1.value = "val"
filters.add(filter1)
let filter2 = VisilabsTargetFilter()
filter2.attribute = "attr2"
filter2.filterType = "0"// There are 2 filter types: Include and Exclude. For Include pass "0", for Exclude pass "1".
filter2.value = "val"
filters.add(filter2)
let targetRequest = Visilabs.callAPI().buildTargetRequest("ZoneID", withProductCode: "ProductCode", withProperties:dic, with:filters)


Talep tamamlandıktan sonra, talebin başarı ya da başarısızlık durumuna bağlı olarak callback fonksiyonu çağrılır, bu nedenle ihtiyaçlarınıza göre callback fonksiyonlarını aşağıda gösterildiği gibi kodlamanız gerekir:

Objective-C

void (^ successBlock)(VisilabsResponse *) = ^(VisilabsResponse * response) { NSLog(@"Response: %@", response.rawResponseAsString); NSArray *parsedArray = [response responseArray]; if(parsedArray){ for (NSObject * object in parsedArray) { if([object isKindOfClass:[NSDictionary class]]){ NSDictionary *product = (NSDictionary*)object; NSString *title = [product objectForKey:@"title"]; NSString *img = [product objectForKey:@"img"]; NSString *code = [product objectForKey:@"code"]; NSString *destURL = [product objectForKey:@"dest_url"]; NSString *brand = [product objectForKey:@"brand"]; double price = [[product objectForKey:@"price"] doubleValue]; double discountedPrice = [[product objectForKey:@"dprice"] doubleValue]; NSString *currency = [product objectForKey:@"cur"]; NSString *discountCurrency = [product objectForKey:@"dcur"]; int rating = [[product objectForKey:@"rating"] intValue]; int comment = [[product objectForKey:@"comment"] intValue]; double discount = [[product objectForKey:@"discount"] doubleValue]; BOOL freeShipping = [[product objectForKey:@"freeshipping"] boolValue]; BOOL sameDayShipping = [[product objectForKey:@"samedayshipping"] boolValue]; NSString *attr1 = [product objectForKey:@"attr1"]; NSString *attr2 = [product objectForKey:@"attr2"]; NSString *attr3 = [product objectForKey:@"attr3"]; NSString *attr4 = [product objectForKey:@"attr4"]; NSString *attr5 = [product objectForKey:@"attr5"]; } } } }; void (^ failBlock)(VisilabsResponse *) =^(VisilabsResponse * response){ NSLog(@"Failed to call. Response = %@", [actFailRes.error description]); };


Swift

let successBlock:(VisilabsResponse!) -> Void = {response in print("Response:\(response.rawResponseAsString)") for object:AnyObject in response.responseArray{ if(object.isKindOfClass(NSDictionary)){ let productObject = object as! NSDictionary; let title = productObject.objectForKey("title") as! String let img = productObject.objectForKey("img") as! String let code = productObject.objectForKey("code") as! String let dest_url = productObject.objectForKey("dest_url") as! String let brand = productObject.objectForKey("brand") as! String let price = productObject.objectForKey("price") as! Double let discountedPrice = productObject.objectForKey("dprice") as! Double let currency = productObject.objectForKey("cur") as! String let discountCurrency = productObject.objectForKey("dcur") as! String let rating = productObject.objectForKey("rating") as! Int let comment = productObject.objectForKey("comment") as! Int let discount = productObject.objectForKey("discount") as! Double let freeShipping =productObject.objectForKey("freeshipping") as! Bool let sameDayShipping=productObject.objectForKey("samedayshipping") as! Bool let attr1 = productObject.objectForKey("attr1") as! String let attr2 = productObject.objectForKey("attr2") as! String let attr3 = productObject.objectForKey("attr3") as! String let attr4 = productObject.objectForKey("attr4") as! String let attr5 = productObject.objectForKey("attr5") as! String } } } let failBlock: (VisilabsResponse!) -> Void = {response in VisilabsHelper.targetLog(response.targetURL) print("Visilabs target call failed.Error=\(response.rawResponseAsString)") }
  • No labels