我制作的应用只有1个应用内购买,当您购买它时,它会移除广告。 如何让应用程序“记住”用户购买它?
例如,我希望true
在用户购买时isPremium
成为true
,但每次我登录应用时, Thread.sleep(3000);
String s=driver.findElement(By.xpath("//div[@id='ldtable_info']")).getText();
String number=s.substring(s.lastIndexOf("of") + 3, s.lastIndexOf(" "));
int c=Integer.parseInt(number);
System.out.println("total entries"+c);
int g=1;
int RowIndex=1;
if(c>10){
try{
WebElement nextPage=driver.findElement(By.xpath("//a[@id='ldtable_next' and @class='paginate_button next']"));
//WebElement nextPageNotAvailable=driver.findElement(By.xpath("//a[@id='ldtable_next' and @class='paginate_button next disabled']"));
while(nextPage.isDisplayed()){
List<WebElement> Rowlist=driver.findElements(By.xpath(TableRowXpath));
for(WebElement rowElement:Rowlist)
{
List<WebElement> columnlist=rowElement.findElements(By.xpath("td"));
int ColumnIndex=1;
int h=0;
for(WebElement colElement:columnlist)
{
System.out.println("Row "+RowIndex+" Column "+ColumnIndex+" Data "+colElement.getText());
String j=colElement.getText();
ExcelLib e=new ExcelLib();
e.createRow("Sheet3", h);
e.setExcelData("Sheet3",h, g, j);
ColumnIndex=ColumnIndex+1;
h++;
}
g++;
RowIndex=RowIndex+1;
}
nextPage.click();
Thread.sleep(5000);
}
}
catch(Exception ei){
List<WebElement> Rowlist=driver.findElements(By.xpath(TableRowXpath));
for(WebElement rowElement:Rowlist)
{
List<WebElement> columnlist=rowElement.findElements(By.xpath("td"));
int ColumnIndex=1;
int h=0;
for(WebElement colElement:columnlist)
{
System.out.println("Row "+RowIndex+" Column "+ColumnIndex+" Data "+colElement.getText());
String j=colElement.getText();
ExcelLib e=new ExcelLib();
e.createRow("Sheet3", h);
e.setExcelData("Sheet3",h, g, j);
ColumnIndex=ColumnIndex+1;
h++;
}
g++;
RowIndex=RowIndex+1;
}
}
}
else{
List<WebElement> Rowlist=driver.findElements(By.xpath(TableRowXpath));
for(WebElement rowElement:Rowlist)
{
List<WebElement> columnlist=rowElement.findElements(By.xpath("td"));
int ColumnIndex=1;
int h=0;
for(WebElement colElement:columnlist)
{
System.out.println("Row "+RowIndex+" Column "+ColumnIndex+" Data "+colElement.getText());
String j=colElement.getText();
ExcelLib e=new ExcelLib();
e.createRow("Sheet3", h);
e.setExcelData("Sheet3",h, g, j);
ColumnIndex=ColumnIndex+1;
h++;
}
g++;
RowIndex=RowIndex+1;
}
}
都不是LPAD
。< / p>
答案 0 :(得分:2)
您可以使用NSUserDefaults
存储与购买IAP相对应的值。
在此示例中,我们使用NSUserDefaults
来检查密钥removeAds
是true
还是false
。在您将密钥设置为if
之前,true
语句将始终执行。有关NSUserDefaults
的更多信息,请参阅NSUserDefaults Class Reference。
// Create this globally
let defaults = NSUserDefaults.standardUserDefaults()
// Check if IAP has been purchased
if !defaults.boolForKey("removeAds") {
// IAP not purchased
// Display ads
}
// Upon the successful purchase of your IAP you set the key to true
defaults.setBool(true, forKey: "removeAds")
NSUserDefaults.standardUserDefaults().synchronize()