从iOS 9和Xcode 7开始,我无法再在iPad(设备和模拟器)上实现UIImagePickerController.以下代码适用于iPad,但仅适用于iOS 9.使用iOS 9+时,显示的图像(在UIImagePickerController被取消后)是所选图像的错误版本.没有重新调整大小或裁剪最终图像只是原始图像的右上角?? 另外一个问题 - 如果imagePicker.allowsEditing = false,你无法从PhotoLibrary中选择图像?
@IBAction func photoButton(sender: AnyObject) {
imagePicker.allowsEditing = true
imagePicker.sourceType = .PhotoLibrary
self.presentViewController(imagePicker, animated: false, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
if let pickedImage = info[UIImagePickerControllerEditedImage] as? UIImage {
self.imageView.image = pickedImage
dismissViewControllerAnimated(true, completion: { () -> Void in
})
}
Run Code Online (Sandbox Code Playgroud)
下面是UIImagePickerController中显示的选定图像的示例.(注意所选图像如何呈现非常小而不像以前那样呈现屏幕的全尺寸/宽度)
在UIImagePickerController中选择使用按钮后,最终图像仅在原始图像的右上角.我在做错了什么或是在iOS 9上破坏了UIImagePickerController?
我想取一个数字字符串并生成一个简单的条形码,任何扫描仪都可以读取.
我已经可以使用相机并读取条形码,但现在我想生成一个条形码.
有谁知道一个允许我这样做,资源或代码snipets的sdk?
谢谢
我将密码存储到iOS钥匙串中,以后再检索它们以在我的应用程序中实现“记住我”(自动登录)功能。
我围绕Security.framework
功能(SecItemCopyMatching()
,等等)实现了自己的包装器,直到iOS 12为止,它的运行都像是一种魅力。
现在,我正在测试我的应用程序不会与即将推出的iOS 13兼容,瞧瞧:
SecItemCopyMatching()
总是回来 .errSecItemNotFound
...即使我以前已经存储了要查询的数据。
我的包装是用静态特性方便地提供的价值类kSecAttrService
和kSecAttrAccount
组装查询字典时:
class LocalCredentialStore {
private static let serviceName: String = {
guard let name = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String else {
return "Unknown App"
}
return name
}()
private static let accountName = "Login Password"
// ...
Run Code Online (Sandbox Code Playgroud)
我将使用以下代码将密码插入钥匙串:
/*
- NOTE: protectWithPasscode is currently always FALSE, so the password
can later be retrieved programmatically, i.e. without user interaction.
*/ …
Run Code Online (Sandbox Code Playgroud) 正如本问题和其他任何地方所讨论的,Apple现在要求应用程序为用户提供一种方法来恢复In App Purchase的已完成交易.
我全力以赴.我的应用程序的第一个版本以某种方式让它在没有它的情况下进行了审核(当时我还没有意识到这个规则,和/或它还没有被强制执行),但后来我开始接收来自用户的大量电子邮件询问缺少的内容(也有数据存储指南,并且不会备份繁重的可下载内容).
所以,假设我在我的UI中的某处包含了一个"恢复"按钮,当点击调用时:
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.用户被提示他的AppleID和/或密码,并且恢复过程开始.
我遇到的问题是:如果没有要恢复的事务,在AppleID提示之后我的应用程序基本上没有任何反应,这可能会让用户感到困惑或使应用程序看起来没有响应或损坏.
我希望能够显示"所有购买都是最新的"或类似的警报视图.
我可以在我的Transaction Observer代码中做些什么来检测这种情况吗?
有没有人认为这将是一个糟糕的设计,UX明智?
我想创建一个类似这样的NSDictionary:
"zones":
{
{
"zoneId": "1",
"locations":
{
{
"locId": "1",
"locZoneId": "1",
"locLatitude": "33.68506785633641",
"locLongitude": "72.97488212585449"
},
{
"locId": “2”,
"locZoneId": "1",
"locLatitude": "33.68506785633641",
"locLongitude": "72.97488212585449"
},
{
"locId": “3”,
"locZoneId": "1",
"locLatitude": "33.68506785633641",
"locLongitude": "72.97488212585449"
},
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何创造.
我已将Swift编译器标志设置-warn-long-function-bodies
为90毫秒,以查看我的项目中的哪些函数编译时间过长(由于类型检查).
我有以下方法:
func someKey(_ sectionType: SectionType, row: Int) -> String {
let suffix = row == 0 ? "top" : "content"
return "\(sectionType)_\(suffix)"
}
Run Code Online (Sandbox Code Playgroud)
(SectionType
是一个String支持的枚举)
如上所述,2017款MacBook Pro 需要96毫秒.我尝试的第一件事是绕过字符串插值而\(sectionType.rawValue)
不是使用\(sectionType)
,但现在它给了我106毫秒.错误的举动......
接下来,我改变了:
let suffix = row == 0 ? "top" : "content"
Run Code Online (Sandbox Code Playgroud)
至:
let suffix = "top"
Run Code Online (Sandbox Code Playgroud)
警告消失了,因此三元运算符导致了问题.
我尝试了这个:
let suffix: String = { // Note the type annotation!
if row == 0 {
return "top"
}
return "content"
}()
Run Code Online (Sandbox Code Playgroud)
...但是现在 …
我一直想知道在什么情况下在objective-C中采用单例模式是非常必要的(例如,定义一个专用类并创建一个单独的实例),使用类作为对象是不行的.
特别是,我正在考虑以下解决方案:
static
变量(文件范围全局变量),而不是单例实例的实例变量;例如,而不是一个Texture
类(模型对象)和一个TextureManager
单(资源管理器),你可以有作为类的方法和相同的静态变量实现的所有纹理制作/清除Texture
类(工厂模式加上一些资源管理).
有关这个设计的任何想法?
编辑:
现在我想到了它,仍然在Texture
上面的例子中,即使我将这两个类分开(Texture
和TextureManager
)我必须在A之间做出选择.让经理成为单身人士,并使用实例方法或B.让经理成为无实体的辅助类.澄清:
Texture* myTexture = [[TextureManager defaultManager] textureWithName:@"TextureName"];
// (singleton, client uses instance methods)
Run Code Online (Sandbox Code Playgroud)
与
Texture* myTexture = [TextureManager textureWithName:@"TextureName"];
// (Class standing in for singleton, client uses class methods)
Run Code Online (Sandbox Code Playgroud)
后者看起来更直接,不那么繁琐/冗长,但我想知道哪种设计"更正确".当然,前者允许TextureManager
出现不止一个实例(不是在我的情况下).
我想使用Git对我的游乐场进行版本控制,但我不确定应该忽略哪些文件以及应该提交哪些文件.
目前我使用以下.gitignore
文件进行游乐场:
# Xcode user data
xcuserdata
Run Code Online (Sandbox Code Playgroud)
那应该还有什么?
我在iOS中采用了Gmail API,我收到了警告:
不推荐使用initWithRequest
在以下行中:
connection_ = [[connectionClass alloc] initWithRequest:request_ delegate:self startImmediately:NO];
Run Code Online (Sandbox Code Playgroud)
该行位于API库的源文件GTMHTTPFetcher.m中.
弃用-initWithRequest:
方法的替代品是什么?