从iOS7 Apple弃用了SKPaymentTransaction实例的transactionReceipt属性,现在我们有一个包含所有内容的大收据.在我的应用程序中,我有几个消耗品购买.我的代码:
#pragma mark -
#pragma mark SKPaymentTransactionObserver
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray<SKPaymentTransaction *> *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
break;
...
}
}
- (void)completeTransaction:(SKPaymentTransaction *)transaction {
// [self sendRecieptToServer:transaction.transactionReceipt]; // deprecated
[self testMainReceipt];
[self deliverPurchaseNotificationFirIdentifier:transaction.payment.productIdentifier];
[SKPaymentQueue.defaultQueue finishTransaction:transaction];
}
- (void)testMainReceipt {
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
[self sendRecieptToServer:receipt]; //look at the 'status' field and determine whether a good purchase or not
}
Run Code Online (Sandbox Code Playgroud)
从Apple的回复中我看到'in_app'提交了一个数组,其中包含一个项目 - …
我有TableView自定义类型的细胞.原型cell我有3个按钮.我希望能够在按下另一个时更改按钮标题.我试着这个:
- (IBAction) doSomething:(id) sender {
CGPoint hitPoint = [sender convertPoint:CGPointZero toView:self.myTableView];
NSIndexPath *hitIndex = [self.myTableView indexPathForRowAtPoint:hitPoint];
NSLog(@"%ld", (long)hitIndex.row); //This works and I can see the row which button placed
MyCustomViewCell *cell = [_myTableView dequeueReusableCellWithidentifier:@"myCell"];
//I'm tried this:
cell.button.titleLabel.text = @"111";
//and I'm tried this:
[cell.button setTitle:@"222" forState:UIControlStateNormal];
}
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath(NSIndexPath *)indexPath {
MyCustomViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"];
if (!cell) {
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"myCell"];
cell.accessoryType= UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text = _productNameForClearance;
cell.imageView.image …Run Code Online (Sandbox Code Playgroud) 我正在尝试获取当前季度的第一个和最后一个日期,我正在使用它:
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitQuarter | NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[NSDate date]];
components.quarter = 1;
funStartDate = [[NSCalendar currentCalendar] dateFromComponents: components];
NSLog(@"First day of quater: %@", funStartDate);
[components setQuarter:[components quarter]+1];
funEndDate = [[NSCalendar currentCalendar] dateFromComponents: components];
NSLog(@"Last day of quater: %@", [funEndDate descriptionWithLocale:[NSLocale currentLocale]]);
Run Code Online (Sandbox Code Playgroud)
但在两个控制台打印中,我看到了今天的日期.我做错了什么?
我有2个实体:目标和类别.我向目标实体添加了关系"类别".我希望该用户可以从列表中选择一个类别,然后将该类别添加为与Goal对象的关系.但我收到错误:-[__NSSingleObjectSetI managedObjectContext]: unrecognized selector sent to instance 0x138a22fa0
我的代码:
- (BOOL)save {
// Get Category object
NSManagedObject *objCategory = [self getCategoryObjectWithID:@"1"];
if (!objCategory) {
NSLog(@"ERROR objCategory fetching!");
return;
}
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Goal"
inManagedObjectContext:[CoreDataWrapper myManagedContext]];
NSManagedObject *goal = [[NSManagedObject alloc] initWithEntity:entity insertIntoManagedObjectContext:[CoreDataWrapper myManagedContext]];
[goal setValue:strID forKey:@"id"];
[goal setValue:[NSSet setWithObject:objCategory] forKey:@"category"]; // here error
return [CoreDataWrapper saveMyContext];
}
- (NSManagedObject *)getCategoryObjectWithID:(NSString *)catID {
// Fetching
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Category"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K == %@", @"categoryID", …Run Code Online (Sandbox Code Playgroud) 我有动态tableView与自定义单元格.CustomCell .h文件如下所示:
@property (strong, nonatomic) IBOutlet UILabel *uslugaName; //I set retain doesn't work too
@property (strong, nonatomic) IBOutlet UILabel *howMuchPayLbl;
Run Code Online (Sandbox Code Playgroud)
我的CellForRowAtIndexPathMethod:
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString * cellIdentifier = @"Cell";
myCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
/*
if (!cell)
cell = [[myCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
*/
if (indexPath.row !=15) {
cell.uslugaName.text =serviceNameArr[indexPath.row];
//?????????? ?????? ? ??????????? ?? ?????????? ??????
if ([uslugaIsActiveArr[indexPath.row] isEqual: @"1"]) {
cell.backgroundColor = [UIColor blackColor];
cell.howMuchPayLbl.enabled = YES;
}
else {
cell.backgroundColor = [UIColor …Run Code Online (Sandbox Code Playgroud) 是的,我知道这个问题在这里非常受欢迎,并且已经为这个问题提供了很多答案,是的,我在这里在视图控制器之间传递数据.但是我很长时间都做不到.
在ViewControllerB.h中我为BOOL创建了一个属性
@property(nonatomic) BOOL *someBool;
Run Code Online (Sandbox Code Playgroud)
ViewControllerA.m:
#import "ViewControllerB.h"
ViewControllerB *viewControllerB = [[ViewControllerB alloc] init];
viewControllerB.someBool = YES;
[self.navigationController pushViewController:viewControllerB animated:YES];
Run Code Online (Sandbox Code Playgroud)
在ViewControllerB.m中ViewDidLoad:
NSLog(@"%@", self.someBool);
Run Code Online (Sandbox Code Playgroud)
但xCode在这一行给我错误(NSLog(@"%@",self.someBool);)并说:Thread 1:EXC_BAD_ACCESS (code =2).我究竟做错了什么?
ios ×6
objective-c ×4
iphone ×2
uitableview ×2
core-data ×1
nscalendar ×1
nsdate ×1
uibutton ×1