CFURLDestroyResource现已弃用.我不确定要使用什么而不是它,并且没有任何运气通过Apple的文档挖掘.
我正在使用BlackRaccoon操作我的FTP服务器,它使用CFURLDestroyResource,这当然导致编译器警告.
我正在使用 SpriteKit 和 Swift 编写一个游戏,但遇到了内存问题。
我的游戏的布局是这样的:GameViewController (UIViewController) 在 viewDidLoad 屏幕中呈现第一个 SKScene (levelChooserScene)。这个场景只是显示一堆按钮。当用户选择按钮时,场景会使用 skView.presentScene 转换到正确的场景,当关卡完成时,该场景会转换回 levelChooserScene,游戏就可以让用户选择下一个关卡。
问题是,当转换回 levelChooserScene 时,为游戏场景分配的内存不会被释放,因此在仅选择几个级别后,我开始收到内存错误。
我的设计从 SKScene 过渡到 SKScene 是否正确,或者我应该每次都返回到 GameViewController,然后从那里过渡到下一个 SKScene?
我在这里找到了一些帖子,说我应该在场景之间调用 skView.presentScene(nil) ,但我对如何或在哪里实现它感到困惑。
我只是想从一个 SKScene 转换到另一个 SKScene,并将传出场景使用的内存返回到系统。
这是我如何实现 SKScene 的示例:
class Level3: SKScene
{
var explodingRockTimer = NSTimer()
var blowingUpTheRocks = SKAction()
override func didMoveToView(view: SKView)
{
NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: "dismissTheScene:", userInfo: nil, repeats: false)
var wait = SKAction.waitForDuration(0.5)
var run = SKAction.runBlock{
// your code here ...
self.explodeSomeRocks()
}
let runIt = SKAction.sequence([wait,run]) …Run Code Online (Sandbox Code Playgroud) 我创建了一个非常简单的应用程序来从我的Web服务器下载文本文件.我有这个与NSURLConnection完美配合,但我正在尝试迁移到NSURLSession.
我遇到的问题是没有调用任何委托方法.
我的服务器受密码保护,因此我需要使用基本的http身份验证来访问该文件,但是从未调用didReceiveChallenge方法.
代码行[getFileTask resume]似乎对任何事都没有影响.
我的设置如下:
@interface ViewController : UIViewController <NSURLSessionDelegate, NSURLSessionDownloadDelegate, NSURLSessionTaskDelegate>
{
NSURLSession *session;
}
Run Code Online (Sandbox Code Playgroud)
从viewDidLoad调用以下方法:
-(void)setUpTheNetworking
{
NSString *fileURL = @"www.mywebsite.com/utility/file.txt";
NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
sessionConfig.allowsCellularAccess = YES;
sessionConfig.timeoutIntervalForRequest = 10;
sessionConfig.timeoutIntervalForResource = 10;
sessionConfig.HTTPMaximumConnectionsPerHost = 1;
session = [NSURLSession sessionWithConfiguration:sessionConfig delegate:self delegateQueue:nil];
NSURLSessionDownloadTask *getFileTask = [session downloadTaskWithURL:[NSURL URLWithString:fileURL]];
[getFileTask resume];
}
Run Code Online (Sandbox Code Playgroud)
我实施的委托方法是:
-(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite
{
NSLog(@"Here we go");
}
-(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes
{
NSLog(@"Here we go");
} …Run Code Online (Sandbox Code Playgroud) 我的程序中有以下三行代码:
NSMutableString *stringOne = [NSMutableString stringWithFormat:@"Hello "];
NSMutableString *stringTwo = [NSMutableString stringWithFormat:@"World"];
NSMutableString *sayIt = [stringOne stringByAppendingString:stringTwo];
Run Code Online (Sandbox Code Playgroud)
尽管它有效,但第三行导致警告从NSString*分配NSMutableString*.
我在这里不知所措,因为我使用的是NSMutableString.
我的情况与我在这里找到的所有其他例子不同.我有一个基于标签的应用程序.在其中一个选项卡上,用户可以按下一个按钮,该按钮可以同时从Web服务器下载多个文件.
我使用NSOperation来执行每个下载,以便我可以利用内置的依赖项.下载都发生在后台线程上,因此应用程序保持响应.最后的下载完成后,我在屏幕上放置了一个alertController,让用户知道它们已经完成.
如果用户在显示警报控制器时选择了不同的选项卡,则会收到警告:"不建议在分离的视图控制器上显示视图控制器"
如果它们仍然在开始下载的相同选项卡上,那么我不会收到警告.我试过更换:
[self presentViewController:alertController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
同
[self.view.window.rootViewController presentViewController:alertController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
但结果是从不出现alertController.
我在主线程上呈现alertController.
我无法预测下载完成时用户将使用哪个选项卡视图控制器,并且真的想要摆脱此警告.
我正在使用Obj-C开发macOS和Xcode 8.
我刚刚在Xcode 9.1中运行了我在iPhone X模拟器上开发的应用程序.当我点击UITextView内部时,不会出现软键盘.它在iPhone 8模拟器中工作正常.为了解决问题,我在iPhone X模拟器上运行了日历应用程序并选择了搜索图标.再次,没有弹出键盘.
其他人看到这种行为或有修复?
我的 OS X 应用程序的 ViewController 中有以下代码:
NSAlert *alert = [NSAlert new];
alert.messageText = @"Connection error";
alert.informativeText = @"You do not appear to be connected to the internet";
[alert addButtonWithTitle:@"Third button"];
[alert addButtonWithTitle:@"Second button"];
[alert addButtonWithTitle:@"Ok"];
[alert beginSheetModalForWindow:[[self view] window] completionHandler:^(NSInteger result) {
NSLog(@"Success");
}];
// [alert runModal];
Run Code Online (Sandbox Code Playgroud)
当此代码执行时,什么也没有发生。如果我注释掉 beginSheetModalForWindow 行并取消注释 [alert runModal],则警报会按预期显示。
我在这里做错了什么,它没有显示为工作表?
objective-c ×3
ios ×2
deprecated ×1
ios11 ×1
ios7 ×1
iphone-x ×1
macos ×1
nsalert ×1
nsstring ×1
nsurl ×1
nsurlrequest ×1
nsurlsession ×1
skscene ×1
sktransition ×1
sprite-kit ×1
swift ×1
xcode ×1
xcode9 ×1