记住Swift中的应用程序内购买数据

时间:2015-08-18 13:32:03

标签: ios iphone xcode swift ipad

我制作的应用只有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>

1 个答案:

答案 0 :(得分:2)

您可以使用NSUserDefaults存储与购买IAP相对应的值。

在此示例中,我们使用NSUserDefaults来检查密钥removeAdstrue还是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()