如果取消SKStoreProductViewController弹出窗口,则屏幕变为白色

时间:2015-12-17 07:24:30

标签: ios in-app-purchase

要跟进这个帖子targeting specific app with iOS in app purchase,所有人都会很好地启动,我会看到目标应用,但是当我按下“取消”(因为这是沙盒中唯一真正的选择)时,屏幕变白了没有回到上一个屏幕。我试过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

1 个答案:

答案 0 :(得分:0)

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

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