小编Sla*_*ast的帖子

如何使用Swift 2从备份中排除文件?

我使用Swift 1.2工作得很好,因为我使用filePath作为字符串.现在,Swift 2希望我们所有人都使用URL路径,即使我正在阅读他们的文档,我也无法使用它.

我有;

var fileName = "myRespondusCSV.csv"

let fileManager = NSFileManager.defaultManager()

let documentsURL = fileManager.URLsForDirectory(NSSearchPathDirectory.DocumentDirectory, inDomains: NSSearchPathDomainMask.UserDomainMask)


if let documentPath: NSURL = documentsURL.first as NSURL! {

    filePath = documentPath.URLByAppendingPathComponent(fileName)
        print(filePath)        
    } else {
        fileManager.createFileAtPath(filePath!.path!,
                                     contents: ("" as String).dataUsingEncoding(NSUTF8StringEncoding)!,
                                     attributes:nil)
        print("file has been created")
    }
}

func excludeFileFromBackup() {

    var error:NSError?
    //var fileToExcludeh = NSURL.fileReferenceURL(filePath!)

    var fileToExcludeh = fileURLWithPath(filePath)

    let success = fileToExcludeh.setResourceValue(true, forKey: NSURLIsExcludedFromBackupKey, error: &error)
}
Run Code Online (Sandbox Code Playgroud)

我得到了'使用未解析的标识符'fileURLWithPath'!

我应该使用绝对URL路径吗?

nsurl ios swift

4
推荐指数
3
解决办法
2695
查看次数

调用 SKRestoreCompletedTransactions 恢复所有事务

我正在尝试执行以下操作;

获取之前的购买,但只加载到用户选择的支付队列中。我不希望用户下载多个恢复的购买。Apple 建议允许用户决定要恢复的内容,这就是我遇到的问题。目前,我允许RestoreCompletedTransactions在用户选择恢复时被调用,但这意味着我必须清除选定的支付队列。这似乎是一个不必要的过程,导致的问题比它解决的问题还多。我确信有一种简单的方法可以做到这一点,但我已经在网上搜索了数小时以寻找解决方案,而 Apple 文档并没有为此提供任何合理的程序。如果有人可以在这里给我一些指导,我将不胜感激。

我购买的这些非消耗品工作正常,这只是让我陷入困境的恢复。

顺便说一句 - 它的 Apple 托管内容!

- (IBAction)buyProduct:(id)sender { //checked!!

NSLog(@"Performing in-app purchase: %@",_product);

SKPayment *payment = [SKPayment paymentWithProduct:_product];
[[SKPaymentQueue defaultQueue] addPayment:payment];

}

- (IBAction)Restore:(id)sender {

NSLog(@"Performing in-app restore_product: %@",_product);
NSLog(@"Performing in-app restore_productID: %@",productID);

[self restoreThePurchase];

}

- (BOOL)restoreThePurchase {

// restore the purchase
[[SKPaymentQueue defaultQueue]restoreCompletedTransactions];

return YES;
}

#pragma mark -
#pragma mark SKPaymentTransactionObserver methods

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {

for (SKPaymentTransaction *transaction in transactions) {
    switch (transaction.transactionState) { …
Run Code Online (Sandbox Code Playgroud)

in-app-purchase ios

1
推荐指数
1
解决办法
1594
查看次数

SKPaymentTransactionObserver 的应用程序委托设置

我已经设置了一个PurchaseViewController工作正常的程序,除了多个应用程序商店登录,我意识到这是SKPaymentQueue.defaultQueue().addTransactionObserver(self). 我需要将其插入到函数Appdelegate的类中DidFinishLaunchingWithOptions。当我这样做时:

import UIKit
import StoreKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, SKPaymentTransactionObserver {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{        
    UINavigationBar.appearance().barTintColor = UIColor(red: 0/255.0, green: 115/255.0, blue: 158/255.0, alpha: 1.0)
    UINavigationBar.appearance().tintColor = UIColor.whiteColor()
    UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]

    SKPaymentQueue.defaultQueue().addTransactionObserver(self)

    // Override point for customization after application launch.
    return true
}
Run Code Online (Sandbox Code Playgroud)

我明白了Type Appdelegate does not conform to protocol "SKPaymentTransactionObserver

有人可以指出我哪里出错了吗?

ios swift

1
推荐指数
1
解决办法
5164
查看次数

标签 统计

ios ×3

swift ×2

in-app-purchase ×1

nsurl ×1