使用iOS 10.0上一个测试版 我曾尝试使用Camera在我的应用程序中扫描条形码,并且它因此运行时错误而崩溃.
此应用程序已崩溃,因为它试图在没有使用说明的情况下访问隐私敏感数据.应用程序的Info.plist必须包含一个NSCameraUsageDescription键,其中包含一个字符串值,向用户解释应用程序如何使用此数据.
将这把钥匙放入plist,但它仍然坠毁?
试图用快速代码计算图像的路径.我得到了这个,我认为在目标C中工作.
[UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.png", [[NSBundle mainBundle] resourcePath], imgName]];
Run Code Online (Sandbox Code Playgroud)
为了获得我的.png图像的路径,我存储在assets.xcassets中.但我现在需要在SWIFT中这样做,而不是客观C.
我需要路径,因为我试图上传我放在CKAssetiCloud中的图像.
使用此代码在TViOS 10.0下设置Multipeer连接.
import UIKit
import MultipeerConnectivity
class MPCHandler: NSObject, MCSessionDelegate {
var peerID: MCPeerID!
var session: MCSession!
var browser: MCBrowserViewController!
var advertiser: MCAdvertiserAssistant? = nil
func setupPeerWithDisplayName (displayName: String) {
peerID = MCPeerID(displayName: UIDevice.current.name)
}
func setupSession() {
session = MCSession(peer: peerID)
session.delegate = self
}
func setupBrowser() {
browser = MCBrowserViewController(serviceType: "my-game", session: session)
}
func advertiseSelf(advertise:Bool) {
if advertise {
advertiser = MCAdvertiserAssistant(serviceType: "my-game", discoveryInfo: nil, session: session)
advertiser!.start()
} else {
advertiser!.stop()
advertiser = nil
}
} …Run Code Online (Sandbox Code Playgroud) 使用xcode 8 beta 6.
类型覆盖功能准备,我看到这个..
但我在寻找
准备(对于segue:UIStoryboardSegue,sender:AnyObject?)
这是一个错误吗?这个类是ViewController的子类?
iOS 11.x 斯威夫特 4.2
创建 cloudKit 共享并为其设置权限。一切看起来都不错并且有效,但是对于缩略图,我收到以下错误消息,这超出了我的范围。它在说什么?
2018-10-10 11:04:14.422093+0200 n2k Memo[12256:5302161] [DocumentManager] 无法关联所选 URL file:///private/var/mobile/Library/Mobile%20Documents/com~apple~ 的缩略图CloudDocs/Desktop/August2018/App/Icons/noun_Puzzle_787736.png 以及收件箱副本文件:///private/var/mobile/Containers/Data/Application/D13D04E1-8700-4B3E-AD0B-710D037B5253/tmp/ch.cqd。 blah-Inbox/noun_Puzzle_787736.png:错误域=QLThumbnail代码=2“(空)”UserInfo={NSUnderlyingError=0x1c444b070 {错误域=GSLibraryErrorDomain代码=3“找不到生成”UserInfo={NSDescription=找不到生成}}}
我的代码看起来像这样......
let share = CKShare(rootRecord: customRecord)
share[CKShare.SystemFieldKey.title] = "Marley" as CKRecordValue
share[CKShare.SystemFieldKey.shareType] = "ch.cqd.blah" as CKRecordValue
let imageData = image2Save.pngData()!
let options = [
kCGImageSourceCreateThumbnailWithTransform: true,
kCGImageSourceCreateThumbnailFromImageAlways: true,
kCGImageSourceThumbnailMaxPixelSize: 300] as CFDictionary
let source = CGImageSourceCreateWithData(imageData as CFData, nil)!
let imageReference = CGImageSourceCreateThumbnailAtIndex(source, 0, options)!
let thumbnail = UIImage(cgImage: imageReference).pngData()
share[CKShare.SystemFieldKey.thumbnailImageData] = thumbnail! as CKRecordValue
Run Code Online (Sandbox Code Playgroud)
image2Save 是我随后显示的有效 UIImage。添加了在屏幕上显示缩略图的代码。缩略图看起来不错。
Adam Jensen做了很棒的工作@制作一些快速代码将图像转换为mov.
https://gist.github.com/acj/6ae90aa1ebb8cad6b47b
上面的工作很棒,但我想用比一般iPad稍微多一点的CPU和一些真实存储设备来完成这项工作,所以我需要在OS X下运行.说起来容易做起来难.
首先,我没有得到UIKit,取而代之的是Cocoa.没有UIImage,取而代之的是NSImage.在黑暗的修正中做一些刺伤; 固定/跳过减少了31个错误降至5.但我需要一些帮助.
func fillPixelBufferFromImage(image: NSImage, pixelBuffer: CVPixelBuffer, contentMode:UIViewContentMode){
CVPixelBufferLockBaseAddress(pixelBuffer, 0)
let data = CVPixelBufferGetBaseAddress(pixelBuffer)
let rgbColorSpace = CGColorSpaceCreateDeviceRGB()
let context = CGBitmapContextCreate(data, Int(self.outputSize.width), Int(self.outputSize.height), 8, CVPixelBufferGetBytesPerRow(pixelBuffer), rgbColorSpace, CGImageAlphaInfo.PremultipliedFirst.rawValue)
CGContextClearRect(context, CGRectMake(0, 0, CGFloat(self.outputSize.width), CGFloat(self.outputSize.height)))
let horizontalRatio = CGFloat(self.outputSize.width) / image.size.width
let verticalRatio = CGFloat(self.outputSize.height) / image.size.height
var ratio: CGFloat = 1
switch(contentMode) {
case .ScaleAspectFill:
ratio = max(horizontalRatio, verticalRatio)
case .ScaleAspectFit:
ratio = min(horizontalRatio, verticalRatio)
default:
ratio = min(horizontalRatio, verticalRatio)
}
let newSize:CGSize = CGSizeMake(image.size.width * …Run Code Online (Sandbox Code Playgroud) 好的,
这将获得系统音量,效果很好。
var volume = AVAudioSession.sharedInstance().outputVolume
print("output volume: \(volume)")
Run Code Online (Sandbox Code Playgroud)
但是我该如何设置系统音量 [在 Swift 中] 请
使用XCode 8 beta 6El Capitan编码Swift 3.0
试图将项目中的这些行转换Swift 2.0为Swift 3.0
let userInfo = ["peer": peerID, "state": state.toRaw()]
NSNotificationCenter.defaultCenter.postNotificationName("Blah", object: nil, userInfo: userInfo)
Run Code Online (Sandbox Code Playgroud)
所以我设法凑齐了这个......
public class MyClass {
static let myNotification = Notification.Name("Blah")
}
let userInfo = ["peerID":peerID,"state":state.rawValue] as [String : Any]
NotificationCenter.default.post(name: MyClass.myNotification, object: userInfo)
Run Code Online (Sandbox Code Playgroud)
它在我运行它时编译并发送通知并使用此行设置一个监听器,但没有userInfo我可以解码?
let notificationName = Notification.Name("Blah")
NotificationCenter.default.addObserver(self, selector: #selector(peerChangedStateWithNotification), name: notificationName, object: nil)
Run Code Online (Sandbox Code Playgroud)
此代码打印"nil",因为没有userInfo ...
func peerChangedStateWithNotification(notification:NSNotification) {
print("\(notification.userInfo)")
}
Run Code Online (Sandbox Code Playgroud) 使用 iOS 13.3.1 Xcode 11.3.1 Swift 5
代码是这样说的,可以编译但不能正确运行。当我在后台运行我的应用程序时,我收到一条错误消息,显示“由于不存在标识符为 1 的后台任务而失败,或者它可能已结束”。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
BGTaskScheduler.shared.register(forTaskWithIdentifier: "ch.blah.refresh", using: nil) { (task) in
self.handleAppRefresh(task: task as! BGAppRefreshTask)
}
return true
}
func applicationDidEnterBackground(_ application: UIApplication) {
scheduleAppRefresh()
}
var request: BGAppRefreshTaskRequest!
func scheduleAppRefresh() {
request = BGAppRefreshTaskRequest(identifier: "ch.blah.refresh")
request.earliestBeginDate = Date(timeIntervalSinceNow: 60)
do {
try BGTaskScheduler.shared.submit(request)
} catch {
print("Could not schedule app refresh: \(error)")
}
} …Run Code Online (Sandbox Code Playgroud)