如果取消 SKStoreProductViewController 弹出窗口,屏幕会变白
Screen goes white if SKStoreProductViewController popup is cancelled
为了跟进这个线程 ,所有启动都很好,我看到了目标应用程序,但是当我按下 "cancel"(因为这是沙盒中唯一真正的选择)时,屏幕变白并且不 return 到上一个屏幕。我试过 dismissViewController,但没有成功。
如有任何帮助,我们将不胜感激。
#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]; }
}
为了跟进这个线程
如有任何帮助,我们将不胜感激。
#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]; }
}