小编shi*_*him的帖子

从swift调用objective-C typedef块

我正试图从swift调用一个方法.该方法是用Objective-C编写的单例

头文件中的块:

typedef void(^VPersonResultBlock)(Person *person, NSError *error);

- (void)askForMe:(VPersonResultBlock)block;
Run Code Online (Sandbox Code Playgroud)

这是该方法的实现.

- (void)askForMe:(VPersonResultBlock)block
{
if (_me) block(_me,nil);
else {
    [Person getMeWithBlock:^(PFObject *person, NSError *error) {
        if (!error) {
            _me = (Person *)person;
            block(_me,nil);
        }

        else if (error) {
            block(nil,error);
        }
        else {
            NSDictionary *userInfo = @{
                                       NSLocalizedDescriptionKey: NSLocalizedString(@"Operation was unsuccessful.", nil),
                                       NSLocalizedFailureReasonErrorKey: NSLocalizedString(@"The operation failed to retrieve the user.", nil),
                                       NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString(@"Check your network connection and try again", nil)
                                       };
            NSError *error = [[NSError alloc] initWithDomain:@"VisesAsyncErrorDomain" code:-10 userInfo:userInfo];
            block(nil,error);
        }
    }]; …
Run Code Online (Sandbox Code Playgroud)

closures objective-c ios objective-c-blocks swift

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

仅在调试配置中将 info.plist 中启用的 iTunes 文件共享设置为 YES

在 Xcode 中,我可以根据我的应用程序的配置(调试与发布)将"Application supports iTunes file sharing"/UIFileSharingEnabled设置设置为YES/NO吗?

我已经看到使用用户定义的构建设置来设置字符串 plist 项目的字符串值的讨论(例如 $(MY_DEFINED_SETTING),但是你能用这个布尔设置来做到这一点吗?这不会完全一样,但只要在构建应用程序的发布版本时它会自动删除,这很好。但是如果我尝试在字段旁边YESNO字段中输入任何内容,它默认为NO

我知道根据配置可以有一个文件的两个不同版本,但是如果没有两个基本上相同的文件的副本会更简单。但是,如果这是最好的解决方案,那么将不胜感激任何有关实施的提示。

谢谢

debugging configuration xcode info.plist ios

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

ios - 使用SIGPIPE和SIG_IGN的信号功能

我加入了一个旧项目,我发现了这一行

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    signal(SIGPIPE, SIG_IGN);
    ....
}
Run Code Online (Sandbox Code Playgroud)

我在文档中找到了这个:

/*
 * For historical reasons; programs expect signal's return value to be
 * defined by <sys/signal.h>.
 */
Run Code Online (Sandbox Code Playgroud)

但我仍然对这条线的目的感到困惑.

ios

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

Ionic iOS App store上传错误NSPhotoLibraryUsageDescription Key

我开发了Ionic 2应用程序.当我尝试将其上传到Apple商店时,他们会拒绝它,并显示以下消息:

缺少Info.plist密钥 - 此应用程序尝试在没有使用说明的情况下访问隐私敏感数据.应用程序的Info.plist必须包含一个NSPhotoLibraryUsageDescription键,其中包含一个字符串值,向用户解释应用程序如何使用此数据.

NSPhotoLibraryUsageDescription在config.xml中添加了密钥

<plugin name="cordova-plugin-camera" spec="https://github.com/apache/cordova-plugin-camera">
                <variable name="CAMERA_USAGE_DESCRIPTION" value="App would like to access the camera." />
                <variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="App would like to access the library." />
</plugin>
Run Code Online (Sandbox Code Playgroud)

但他们仍然以同样的信息拒绝了应用程序.我是否需要在所有插件变量中添加此键?我的意思是我也使用了图像选择器插件.我是否还需要在此插件中添加此密钥?我已经添加了,但他们仍然拒绝同样的错误.

app-store ios cordova ionic2

3
推荐指数
2
解决办法
4820
查看次数

Swift字符串索引将"\ r \n"组合为一个char而不是两个

我正在处理包含\r\nSwift 4.2的字符串.我遇到了一些Swift索引的奇怪行为,它看起来\r\n会被Swift索引方法视为一个字符而不是两个字符.我写了一段代码来表达这种行为:

var text = "ABC\r\n\r\nDEF"

func printChar(_ lower: Int, _ upper: Int) {
    let start = text.index(text.startIndex, offsetBy: lower)
    let end = text.index(text.startIndex, offsetBy: upper)
    print("\"" + text[start..<end] + "\"")
}

printChar(0, 1) // "A"
printChar(1, 2) // "B"
printChar(2, 3) // "C"
printChar(3, 4) // new line
printChar(4, 5) // new line (okay, what's going on here?)
printChar(5, 6) // "D"
printChar(6, 7) // "E"
printChar(7, 8) // "F"
Run Code Online (Sandbox Code Playgroud)

打印结果将是

"A"
"B"
"C"
" …
Run Code Online (Sandbox Code Playgroud)

string swift swift4

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

“withUnsafeMutableBytes”已弃用:使用“withUnsafeMutableBytes&lt;R&gt;”

我对 Xcode 很陌生(提前道歉)。尝试将一些旧代码带入生活。尝试迁移到 Swift 5 时获得以下信息。

withUnsafeMutableBytes' 已弃用:withUnsafeMutableBytes<R>(_: (UnsafeMutableRawBufferPointer) throws -> R) rethrows -> R改用

目标:我需要做的就是适当修改代码并完成。

我查看了其他 Stack Overflow 消息,搜索了各种文章,尝试了不同的东西,但无法快速确定需要更改的内容。我确信对于了解更多的人来说,解决方案非常简单。

var responseData = Data(count: Int(responseDataLength))

        _ = responseData.withUnsafeMutableBytes
        {
            mfError = MFMediaIDResponse_GetAsString(mfMediaIdResponsePtr.pointee, MFString($0), responseDataLength)
        }
Run Code Online (Sandbox Code Playgroud)

swift5

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

Xcode 11 Beta 7命令PhaseScriptExecution失败,退出代码为非零([CP] Copy Pods Resources)

最近下载了Xcode 11 Beta,以在iOS 13中测试我的应用程序,但遇到了一个似乎无法解决的问题。每次在[CP] Copy Pods Resources步骤上构建都会失败,并说“命令PhaseScriptExecution失败,退出代码非零”。现在我知道这是任何运行脚本阶段失败时的错误,但是通常会伴随此错误提供一些有用的信息。

错误输出:

ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target 11.0 --output-format human-readable-text --compile /Users/chris/Library/Developer/Xcode/DerivedData/SmartPager-dcfjsnhrgkjfeabbvafghvwsrsxr/Build/Products/Debug-iphoneos/SmartPager Sandbox.app/JSQMessagesViewController.nib 
/Users/chris/Work/projectname/Pods/JSQMessagesViewController/JSQMessagesViewController/Controllers/JSQMessagesViewController.xib --sdk /Users/chris/Downloads/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.0.sdk --target-device ipad --target-device iphone
2019-09-06 13:26:17.003 IBAgent-iOS[39395:514843] Incorrect screen size for <UIScreen: 0x7fb0e05245a0; bounds = {{0, 0}, {0, 0}}> in UICollectionViewData
ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target 11.0 --output-format human-readable-text --compile /Users/chris/Library/Developer/Xcode/DerivedData/SmartPager-dcfjsnhrgkjfeabbvafghvwsrsxr/Build/Products/Debug-iphoneos/SmartPager Sandbox.app/JSQMessagesCollectionViewCellIncoming.nib /Users/chris/Work/projectname/Pods/JSQMessagesViewController/JSQMessagesViewController/Views/JSQMessagesCollectionViewCellIncoming.xib --sdk /Users/chris/Downloads/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.0.sdk --target-device ipad --target-device iphone
Command PhaseScriptExecution failed with a nonzero exit code
Run Code Online (Sandbox Code Playgroud)

相关信息:据我所知,这可能与我们使用的已弃用的cocoapod有关,特别是JSQMessagesViewController(7.3.5)。显然,使用不赞成使用的库并不是很好,但是它可以在Xcode 10中构建并正常运行,因此我不知道问题可能出在哪里。在一个单独的项目中,我尝试仅添加此pod,它会引发相同的错误。关于“屏幕大小不正确...”的行似乎只是警告而不是错误,因为在Xcode 10中,它使用同一行正确编译。

我尝试过重新启动计算机,清理,删除派生数据以及所有常见的东西。我只是不知道现在还能去哪里。任何建议将不胜感激。谢谢!

xcode ios ios13 xcode11

3
推荐指数
2
解决办法
710
查看次数

与 ios 中的 .overFullScreen 演示样式相比,使用 .fullScreen 演示样式的好处

我很想知道如果我们使用.fullScreenvs.overFullScreen presentation style while presenting a view controller modally over rootViewController in an iOS app.

.overFullScreen如果presentedViewController有透明度,我阅读 using将不必要地显示它下面的内容,但如果我使用,.fullScreen那么在透明度后面也会有一个灰色的屏幕,看起来不太好。所以我不确定这有什么好处。

presentmodalviewcontroller ios uimodalpresentationstyle

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

从App Store更新应用程序时是否删除了应用程序的核心数据库?

我在App Store上有一个应用程序,现在是第二个版本.该应用程序使用Core Data存储我不希望在安装应用程序升级时丢失的信息.

我的问题是,如果用户在iPad上安装了1.0版并且数据存储在其核心数据库中,那么在下载并安装1.1版更新时是否会删除此数据库?

core-data ipad ios6

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

iOS中的textColor和tintColor有什么区别?

我知道这是一个愚蠢的问题,但我无法弄清楚它们textColortintColor属性之间的确切区别UIButton.

textcolor uibutton tintcolor ios

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