ios - 如果取消 SKStoreProductViewController 弹出窗口,屏幕会变白

标签 ios in-app-purchase

跟进此线程 targeting specific app with iOS in app purchase ,所有启动都很好,我看到了目标应用程序,但是当我按下“取消”(因为这是沙盒中唯一真正的选择)时,屏幕变白并且不会返回到上一个屏幕。我尝试过解雇ViewController,但没有运气。

如有任何帮助,我们将不胜感激。

#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>

@interface RLDetailsViewControllerINV : UIViewController <SKStoreProductViewControllerDelegate, UITabBarDelegate> {
}

@property (strong, nonatomic) IBOutlet UIButton *purchaseItemText;
@property (strong, nonatomic) IBOutlet UITextView *textView;

- (void) purchased;

- (IBAction)PurchaseItem:(id)sender;
@property(nonatomic, strong) IBOutlet UITextView *textField;
@end



#import "RLDetailsViewControllerINV.h"
@interface RLDetailsViewControllerINV ()
@end

@implementation RLDetailsViewControllerINV
@synthesize textField;



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}


- (void)viewDidLoad {
[super viewDidLoad];
_textView.text = @"Support Sea of Change\n\n100% of proceeds goes to conservation";
[_purchaseItemText setTitle:@"Purchase" forState:UIControlStateNormal];


// Invertebrates
self.textField.text = @"Sea of Change presents the wonderful world of invertebrates\n\n\nThis app is the most comprehensive app on the market with all maters invertebrates, making this perfect for divers and snorkelers alike, to assist them with all of their identification needs.\n\nAlong with Vertebrates (also included in the bundle), these apps cover a whopping 1,670 species, with 2,225 professional photographs.\n\nCorals (317 species)\n- Hard corals\n- Soft corals\n- Sea anemones\n- Hydroids\n- Sea fans\n- Sponges\n- Zoas\n\nCepholopods (14 species)\n- Octopuses\n- Cuttlefish\n\nGastropods (173 species)\n- Nudibranches\n- Sea slugs (non nudibranch tribe)\n- Flat worms\n- Snails & Sea hares\n\nPlus crustaceans, annelids and echinoderms.\n\n\nThere are 559 different species in this app that are all documented and professionally photographed (738+ photos) making this the most comprehensive app on the market for identifying and classifying all invertebrate species.\n";

// \n creates a new line

NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:textField.text];
//
//    UIFont *font_regular=[UIFont fontWithName:@"HelveticaNeue" size:14.0f];

UIFont *font=[UIFont fontWithName:@"HelveticaNeue" size:14.0f];
UIFont *font_bold=[UIFont fontWithName:@"HelveticaNeue-Bold" size:15.0f];
UIFont *font_boldLarge=[UIFont fontWithName:@"HelveticaNeue-Bold" size:17.0f];

NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init] ;
[paragraphStyle setAlignment:NSTextAlignmentCenter];


// the below sets the special format.  First number is which letter to start, and second number indicates how many letters are effected.

[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, 925)];
[attString addAttribute:NSFontAttributeName value:font_boldLarge range:NSMakeRange(0, 60)];
[attString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, 60)];
[attString addAttribute:NSFontAttributeName value:font_bold range:NSMakeRange(390, 6)];
[attString addAttribute:NSFontAttributeName value:font_bold range:NSMakeRange(494, 11)];
[attString addAttribute:NSFontAttributeName value:font_bold range:NSMakeRange(545, 10)];
[attString addAttribute:NSFontAttributeName value:font_bold range:NSMakeRange(660, 11)];
[attString addAttribute:NSFontAttributeName value:font_bold range:NSMakeRange(673, 8)];
[attString addAttribute:NSFontAttributeName value:font_bold range:NSMakeRange(686, 11)];

[self.textField setAttributedText:attString];

}

-(void)viewDidAppear:(BOOL)animated{
// this makes the UITextView iniate on top of view, not middle or bottom
//    [self.textField scrollRangeToVisible:NSMakeRange(0, 0)];
[self.textField setContentOffset:CGPointMake(0.0, 0.0) animated:NO];
}


- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}

- (IBAction)close:(id)sender {
[self dismissViewControllerAnimated:YES completion:NULL];
}


- (IBAction)PurchaseItem:(id)sender {

SKStoreProductViewController *productVC = [[SKStoreProductViewController alloc] init];
productVC.delegate = self;

NSDictionary *productParameters = @{ SKStoreProductParameterITunesItemIdentifier: @"1015807490" };
[productVC loadProductWithParameters:productParameters completionBlock:^(BOOL result, NSError *error) {
    if (error) {
        // sad face :(
        _textView.text = @"Sorry\n\nBut your transaction failed. ";

    }

    if (result) {
        [self presentViewController:productVC animated:NO completion:nil];
        [self purchased];
    }
}];
}

- (void) purchased {

_textView.text = @"Thank you for supporting the Sea of Change foundation";
_purchaseItemText.enabled = NO;
[_purchaseItemText setTitle:@"Purchased" forState:UIControlStateDisabled];
}

-(IBAction)popBackOne:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}

@end

最佳答案

好的,找到了。我添加了以下 void 语句来关闭 VC

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)productVC
{
if (productVC)
{ [self dismissViewControllerAnimated:YES completion:nil]; }
}

关于ios - 如果取消 SKStoreProductViewController 弹出窗口,屏幕会变白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34328854/

相关文章:

objective-c - 向下滚动时在表格 View 上附加数据

ios - 通过导入的数据库swift进行SQL查询

ios - 阻止 iOS 应用程序休眠但保留锁屏和屏幕调光

ios - Swift 生成的 header 缺少外部 swift 框架

iOS 为应用程序内容购买本地货币

delphi - 带有应用内购买功能的Delphi XE2 iOS应用

ios - 免费为用户提供付费应用内购买

iphone - 我可以使用应用内购买来租借视频吗?

ios - 在 UITableViewCell 中绘制一个彩色圆圈

android - Android 应用内购买虚拟商品的可用性流程