我在iOS10中安排新通知,如下所示:
func scheduleNotification (event : Meeting, todaysBadgeCounter: Int) {
if #available(iOS 10.0, *) {
let minutesBefore = 10
//interval in seconds from current point in time to notification
let interval : NSTimeInterval = NSTimeInterval(secondsFromNowTo(event.startTime.dateByAddingTimeInterval(-minutesBefore * 60)))
//only schedule in the future
if(interval > 0){
let category = NotificationsController.notificationCategory
let center = NotificationsController.notificationCenter
center.setNotificationCategories([category])
let content = UNMutableNotificationContent()
content.title = NSString.localizedUserNotificationStringForKey(event.title, arguments: nil)
if(minutesBefore <= 1){
content.body = NSString.localizedUserNotificationStringForKey("IOS10: Your \(event.title) is about to start", arguments: nil)
}else{
content.body = NSString.localizedUserNotificationStringForKey("IOS10: …Run Code Online (Sandbox Code Playgroud) 我正在尝试从iphone上的URL加载图像,图像在那里,我可以在safari中使用相同的链接打开它,但不能在应用程序中打开它:
Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname
could not be found." UserInfo={NSUnderlyingError=0x17024f810
{Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)"
UserInfo={_kCFStreamErrorCodeKey=50331647, _kCFStreamErrorDomainKey=6147928288}},
NSErrorFailingURLStringKey=https://........, NSErrorFailingURLKey=https://.........
Run Code Online (Sandbox Code Playgroud)
请求代码:
func downloadImage(userEmail: String, onCompletion: @escaping (UIImage) -> Void) {
print("Download Started")
let route = "\(baseURL as String)\(userEmail as String)\(baseURLparameters as String)"
let url = URL(string: route)
getDataFromUrl(url: url!) { (data, response, error) in
guard let data = data, error == nil else {
print("===failed:", error ?? "dunno")
print("===url:", url?.absoluteString ?? "dunno")
return
}
print(response?.suggestedFilename ?? url!.lastPathComponent …Run Code Online (Sandbox Code Playgroud) 我有一个拆分视图控制器,左侧有一个项目列表,右侧有一个详细视图.AppDelegate中的相关代码:
let splitViewController = mainView.instantiateViewControllerWithIdentifier("initial") as! UISplitViewController
let rightNavController = splitViewController.viewControllers.last as! UINavigationController
let detailViewController = rightNavController.topViewController as! DetailsIpad
let leftNavController = splitViewController.viewControllers.first as! UINavigationController
let masterViewController = leftNavController.topViewController as! MainViewController
masterSplitViewController = masterViewController
detailSplitViewController = detailViewController
// Override point for customization after application launch.
let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as! UINavigationController
navigationController.topViewController!.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem()
splitViewController.delegate = self
self.window!.rootViewController = splitViewController
Run Code Online (Sandbox Code Playgroud)
当我第一次启动应用程序时,我发现拆分屏幕的右侧部分占用了所有屏幕:
如果我旋转屏幕,它会被正确设置(可能因为两个视图都出现在屏幕上):
当我在任何地方设置断点时,我看到右侧的详细视图在左侧的主视图(项目列表)之前加载,尽管没有直接调用.我无法更改分屏的视图的调用顺序.我怎样才能解决这个问题?
更新:
我可以在显示拆分视图控制器之前设置它:
splitViewController.preferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible
Run Code Online (Sandbox Code Playgroud)
在我打印时,在分割控制器的ViewDidLoad中:
print(self.preferredDisplayMode.rawValue)
Run Code Online (Sandbox Code Playgroud)
我得到:2,这是AllVisible.但结果仍然相同.
我需要在Xcode中为Unit Test创建多个日历事件.由于访问权限请求,呼叫需要是异步的:
eventStore.requestAccess(to: EKEntityType.event, completion: {
granted, error in
//create events
})
Run Code Online (Sandbox Code Playgroud)
这是在setUp()循环中完成的,以创建多个事件.问题是,当测试开始运行时,并非所有完成块都已完成.我已实施该waitForExpectations()方法,使其等到计数器满足要求.但是我收到以下错误消息:
Stall on main thread
Run Code Online (Sandbox Code Playgroud)
这是相关的代码 - setUp:
override func setUp()
{
super.setUp()
if let filepath = Bundle.main.path(forResource: "MasterCalendar", ofType: "csv") {
do {
let expectationCreation = expectation(description: "create events expectation")
let contents = try String(contentsOfFile: filepath)
//print(contents)
let testDataArray = importTestDataArrayFrom(file: contents)
createTestEvents(testDataArray: testDataArray)
{ (eventsArray) in
self.testEvents = eventsArray
print("finished creating events")
expectationCreation.fulfill()
}
waitForExpectations(timeout: 10.0) { (error) in
if error != …Run Code Online (Sandbox Code Playgroud) 我正在尝试从通知中实施操作.到目前为止,我能够触发正确的委托功能,但点击后应用程序不会被带到前台.
相关代码:
@available(iOS 10.0, *)
func registerCategory() -> Void{
print("register category")
let callNow = UNNotificationAction(identifier: "call", title: "Call now", options: [])
let clear = UNNotificationAction(identifier: "clear", title: "Clear", options: [])
let category : UNNotificationCategory = UNNotificationCategory.init(identifier: "IDENT123", actions: [callNow, clear], intentIdentifiers: [], options: [])
let center = UNUserNotificationCenter.currentNotificationCenter()
center.setNotificationCategories([category])
}
@available(iOS 10.0, *)
func scheduleNotification(event : String, interval: NSTimeInterval) {
print("schedule ", event)
let content = UNMutableNotificationContent()
content.title = event
content.body = "body"
content.categoryIdentifier = "CALLINNOTIFICATION"
let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个自动扩展的自定义单元格.我正在使用这个github示例:https://github.com/rcdilorenzo/Cell-Expander
这一行给出了运行时错误SIGABRT:
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
(cell as! EventTableViewCell).watchFrameChanges()
//Could not cast value of type 'UITableViewCell' (0x105aa1b80) to 'AppName.EventTableViewCell' (0x104287fe0).
}
Run Code Online (Sandbox Code Playgroud)
我也检查了这篇文章的答案,接着是三个步骤,但没有运气: 无法将'UITableViewCell'类型的值转换为'(AppName).(CustomCellName)'
我的自定义单元类看起来像这样:
import UIKit
class EventTableViewCell : UITableViewCell {
...
}
Run Code Online (Sandbox Code Playgroud)
的cellForRowAtIndexPath:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier( "eventCell", forIndexPath: indexPath)
let date = self.eventArray[indexPath.row].startTime
let calendar = NSCalendar.currentCalendar()
let minutes = calendar.component(NSCalendarUnit.Minute, fromDate: date)
var minutesString: String
if (minutes …Run Code Online (Sandbox Code Playgroud) 如果单击“操作”,则通知setAutoCancel(true)不起作用
我有一个通知,其中包含操作。当我点击通知时,它将从列表中删除。但是,当我单击“操作”时,它成功完成了该操作(即拨打电话),但是当我返回到通知列表时,它仍然存在。AlarmReceiver的相对代码:
public class AlarmReceiver extends BroadcastReceiver {
Meeting meeting;
/**
* Handle received notifications about meetings that are going to start
*/
@Override
public void onReceive(Context context, Intent intent) {
// Get extras from the notification intent
Bundle extras = intent.getExtras();
this.meeting = extras.getParcelable("MeetingParcel");
// build notification pending intent to go to the details page when click on the body of the notification
Intent notificationIntent = new Intent(context, MeetingDetails.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
notificationIntent.putExtra("MeetingParcel", meeting); // send meeting that we received to …Run Code Online (Sandbox Code Playgroud) 我试图在for循环中安排一系列通知.安排后,我正在阅读所有待处理的通知(仅用于测试目的).
调度(从for循环调用):
func scheduleNotification (event : Meeting, todaysBadgeCounter: Int) {
if #available(iOS 10.0, *) {
let minutesBefore = CallIn.Settings.notifyNumberOfMinutesBeforeEvent
let notifyBefore = UNNotificationAction(identifier: NotificationActions.NotifyBefore.rawValue, title: "Notification", options: [])
let category = UNNotificationCategory(identifier: "CALLINNOTIFICATION", actions: [notifyBefore], intentIdentifiers: [], options: [])
UNUserNotificationCenter.currentNotificationCenter().setNotificationCategories([category])
let content = UNMutableNotificationContent()
content.title = NSString.localizedUserNotificationStringForKey(event.title, arguments: nil)
if(minutesBefore <= 1){
content.body = NSString.localizedUserNotificationStringForKey("Your \(event.title) is about to start", arguments: nil)
}else{
content.body = NSString.localizedUserNotificationStringForKey("You have \(event.title) in \(Int(minutesBefore)) minutes", arguments: nil)
}
content.sound = UNNotificationSound.defaultSound()
//interval in seconds …Run Code Online (Sandbox Code Playgroud) 我正在使用UNUserNotificationCenter实施新通知.但我需要保持向后兼容,因此我在所有地方都进行了检查:
if #available(iOS 10.0, *) { ... }
else { ... }
Run Code Online (Sandbox Code Playgroud)
这似乎在iOS10中运行良好.为了能够使用UNUserNotificationCenter框架,我必须导入:
import NotificationCenter
Run Code Online (Sandbox Code Playgroud)
但它崩溃了iOS9.3,因为它不知道它是什么.它是一个编译时动作,而不是运行时动作 - 所以它意味着我不能在imports上放置条件.如果我创建一个单独的类,并且放
@available(iOS 10.0, *)
class ....
Run Code Online (Sandbox Code Playgroud)
那里的进口也在课堂实施之前发生. 我应该如何解决这个问题?
我有一个应用程序,它从远程 API 获取带有图像 URL 的项目列表,然后它必须从该项目位置内的给定 url 获取每个项目的图像。问题是,当上下滚动并因此从视图中删除列表项并将它们移回到视图中时,它们确实会出现。然而,在初始加载时,它们永远保持“加载”状态,直到移出和移入。我的代码:
import SwiftUI
struct ContentView: View {
@EnvironmentObject var artObjectStore: ArtObjectStore
@State private var pageCount = 1
@State private var tappedLink: String? = nil
@Environment(\.imageCache) var cache: ImageCache
var body: some View {
NavigationView {
Form {
Section(header: Text("Art")) {
List {
ForEach(artObjectStore.artObjects, id: \.self) { artObject in
self.link(for: artObject)
}
Button(action: loadMore) {
Text("")
}
.onAppear {
DispatchQueue.global(qos: .background).asyncAfter(deadline: DispatchTime(uptimeNanoseconds: 10)) {
self.loadMore()
}
}
}
}
}
.navigationBarTitle("Art objects")
}
.onAppear(perform: loadMore) …Run Code Online (Sandbox Code Playgroud) xcode ×5
ios ×4
ios10 ×4
swift ×4
swift2 ×4
android ×1
combine ×1
dismiss ×1
ekeventkit ×1
eventkit ×1
httprequest ×1
ipad ×1
swift2.3 ×1
swiftui ×1
uitableview ×1
unit-testing ×1