我试图以这种方式注册本地通知的应用程序:
UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Alert | UIUserNotificationType.Badge, categories: nil))
Run Code Online (Sandbox Code Playgroud)
在Xcode 7和Swift 2.0中 - 我收到错误Binary Operator "|" cannot be applied to two UIUserNotificationType operands.请帮我.
我需要在Swift中获取iOS设备的IP地址.这不是关于此的其他问题的重复!我需要只获得WiFi IP地址,如果没有wifi地址 - 我需要处理它.Stack Overflow上有一些关于它的问题,但是只有返回ip地址的函数.例如(来自如何在swift中获取IP地址):
func getIFAddresses() -> [String] {
var addresses = [String]()
// Get list of all interfaces on the local machine:
var ifaddr : UnsafeMutablePointer<ifaddrs> = nil
if getifaddrs(&ifaddr) == 0 {
// For each interface ...
for (var ptr = ifaddr; ptr != nil; ptr = ptr.memory.ifa_next) {
let flags = Int32(ptr.memory.ifa_flags)
var addr = ptr.memory.ifa_addr.memory
// Check for running IPv4, IPv6 interfaces. Skip the loopback interface.
if (flags & (IFF_UP|IFF_RUNNING|IFF_LOOPBACK)) == (IFF_UP|IFF_RUNNING) { …Run Code Online (Sandbox Code Playgroud) 大多数iOS应用程序都有一个以图像为背景的视图.那里有图像尺寸指南吗?例如,这是在Sketch中设计的iOS屏幕:
如您所见,有一个背景图像.现在每个应用程序都应该支持许多Apple设备.新的iOS 10支持从iPhone 5到iPhone 6s Plus的所有设备.它们具有不同的屏幕尺寸和分辨率.在创建Xcode资产时,我给出了3个不同大小的背景图像 - @1x, @2x, @3x.它们的尺寸应该是多少?
我正在做HTTP请求并得到我的响应func.它返回响应的值.我是这样做的:
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) {(response, data, error) in
println(NSString(data: data, encoding: NSUTF8StringEncoding))
stringResponse = NSString(data: data, encoding: NSUTF8StringEncoding) as! String
if stringResponse == "0" {
return false
} else if stringResponse == "1" {
return true
} else {
return false
}
}
Run Code Online (Sandbox Code Playgroud)
但在所有returns我有错误Unexpected non-void return value in void function如何解决这个问题?
我有一个AVAudioPlayer实例,它在内存中加载声音audioPlayer.prepareToPlay(),然后在几次开始播放之后.我有一个问题,在进入背景后大约十分钟内,它从记忆中泄漏,我没有准备好.在那个喂食时间之后,我没有能力prepareToPlay()再次跑步.如何长时间将预装的声音留在内存中?我准备声音播放applicationDidFinishLaunchingWithOptions方法:
let dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
dispatch_async(dispatchQueue, {[weak self] in
var audioSessionError: NSError?
let audioSession = AVAudioSession.sharedInstance()
NSNotificationCenter.defaultCenter().addObserver(self!, selector: "handleInterruption:", name: AVAudioSessionInterruptionNotification, object: nil)
audioSession.setActive(true, error: nil)
if (audioSession.setCategory(AVAudioSessionCategoryPlayback, error: &audioSessionError)) {
println("Successfully set the audio session")
} else {
println("Could not set the audio session")
}
let filePath = NSBundle.mainBundle().pathForResource("sound", ofType:"mp3")
let fileData = NSData(contentsOfFile: filePath!, options: .DataReadingMappedIfSafe, error: nil)
var error:NSError?
self!.audioPlayer = AVAudioPlayer(data: fileData, error: &error)
self!.audioPlayer?.numberOfLoops = -1
self!.audioPlayer?.delegate = …Run Code Online (Sandbox Code Playgroud) 我正在尝试连接到 Oracle Express 11g。我正在将 ODAC 12c 与 Visual Studio 2015 结合使用。以下是我尝试连接的方式:
OracleConnection con;
con = new OracleConnection("User Id=SYSTEM;Password=manager;Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.1.22)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = XE)))");
con.Open();
Run Code Online (Sandbox Code Playgroud)
应用程序崩溃并给出Exception(不是OracleException):Object reference not set to an instance of an object.如果我不设置连接字符串,它会OracleException按预期给出。怎么了?
有没有人尝试过在 iOS 14 Widget 中更新用户的位置?在阅读了 Apple Developer 论坛后,我想出了编写包装器CLLocationManager并以这种方式使用它:
class WidgetLocationManager: NSObject, CLLocationManagerDelegate {
var locationManager: CLLocationManager? {
didSet {
self.locationManager!.delegate = self
}
}
private var handler: ((CLLocation) -> Void)?
func fetchLocation(handler: @escaping (CLLocation) -> Void) {
self.handler = handler
self.locationManager!.requestLocation()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
self.handler!(locations.last!)
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print(error)
}
}
Run Code Online (Sandbox Code Playgroud)
并以这种方式使用它:
var widgetLocationManager = WidgetLocationManager()
func getTimeline(for configuration: SelectPlaceIntent, in context: Context, completion: @escaping (Timeline<Entry>) …Run Code Online (Sandbox Code Playgroud) 我正在尝试区分 SwiftUI 中的双击和三次点击手势识别器。在基于故事板的应用程序中,可以使用 来完成UIGestureRecognizerDelegate,但在 SwiftUI 中我还没有找到任何解决方案。
笔记:
以下不起作用:
.onTapGesture(count: 3) {
print("Triple Tap!")
}
.onTapGesture(count: 2) {
print("Double Tap!")
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用UIScrollViewDelegate:
class ViewController: UIViewController <UIScrollViewDelegate> {}
Run Code Online (Sandbox Code Playgroud)
但我有错误: Cannot specialize non-generic type 'UIViewController'
我做了一个自定义,UINavigationBar看起来像这样:[![1]](https://i.stack.imgur.com/gMHQ8.png)
现在我想增加左栏按钮和左栏按钮之间的间距。我试图用这种方式做到这一点UIEdgeInsets:
self.navigationItem.leftBarButtonItem?.imageInsets = UIEdgeInsetsMake(0, 20, 0, 0)
Run Code Online (Sandbox Code Playgroud)
然后它就会尖叫
:
ios ×9
swift ×6
background ×1
c# ×1
insets ×1
memory-leaks ×1
odac ×1
oracle ×1
swift2 ×1
swiftui ×1
uiedgeinsets ×1
widgetkit ×1