2016-05-21 14 views
0

我正在測試我的應用程序購買與測試accound和一切都很好。我無意中發現了一些問題。我正在購買中,警報繼續「你想購買...」,我按下HOME按鈕,當我再次開始申請時,它沒有清楚排隊?所以我開始接受彈出登錄...它被堵在隊列中。我需要幫助,如果應用程序終止如何實現,以自動清除隊列。所以如果有人可以爲此發佈代碼。 Tnx交易在購買過程中陷入隊列中

+0

您應該添加更多的上下文。根據你的問題,我們不知道你在做什麼。發佈一些相關的代碼,你是否也閱讀過Apple的文檔? –

回答

0

我想我通過將觀察者放在appDelegate中解決了這個問題。

import UIKit 
import StoreKit 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 

var window: UIWindow? 

var transactionObserver: PurchaseViewController! 



func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
    transactionObserver = PurchaseViewController() 
    SKPaymentQueue.defaultQueue().addTransactionObserver(transactionObserver) 

    // Override point for customization after application launch. 
    return true 
} 

func applicationWillResignActive(application: UIApplication) { 
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 
} 

func applicationDidEnterBackground(application: UIApplication) { 
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 

    transactionObserver = PurchaseViewController() 
    SKPaymentQueue.defaultQueue().removeTransactionObserver(transactionObserver) 
} 

func applicationWillEnterForeground(application: UIApplication) { 
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 
} 

func applicationDidBecomeActive(application: UIApplication) { 
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
} 

func applicationWillTerminate(application: UIApplication) { 
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 
    transactionObserver = PurchaseViewController() 
    SKPaymentQueue.defaultQueue().removeTransactionObserver(transactionObserver) 
} 


} 
相關問題