在obj-C中,当使用与我的应用程序关联的文件或链接轻触另一个iOS应用程序(邮件附件,Web链接)时.然后我会在openURL上捕获它,didFinishLaunchingWithOptions并显示一个UIAlertView确认用户想要导入数据.现在这UIAlertView是折旧的我试图做同样的事情,但不是真的确定最好的方法来做到这一点?
当我的应用程序从另一个应用程序接收数据时,我无法显示简单警报.此代码在Objective-C中运行良好,具有UIAlertView:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
if (url)
{
self.URLString = [url absoluteString];
NSString *message = @"Received a data exchange request. Would you like to import it?";
importAlert = [[UIAlertView alloc] initWithTitle:@"Data Received" message:message delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
[importAlert show];
}
return YES;
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试切换到UIAlertViewControllerSwift时,我似乎找不到一种简单的方法来显示消息:
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
let URLString: String = url.absoluteString!
let message: …Run Code Online (Sandbox Code Playgroud) 我想使用PDF而不是创建像素特定的图标.XCode(6和6.1)将在编译图标期间从PDF构建特定于设备的像素图像,但我无法弄清楚如何为AppIcon(Springboard App Icon)完成此操作.
Icon集合似乎与AppIcon集合不同(图标为.imageset,App图标为.appiconset)
想知道是否有人对此有任何好运?
也许XCode(v6.1)尚不具备此功能?
只想阅读Swift中的启动选项.
这是我的旧obj-C代码,工作正常:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *URL = [launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];
if (URL)
Run Code Online (Sandbox Code Playgroud)
这就是我认为Swift代码应该是这样的:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
if let options = launchOptions
{
let URL: NSURL = options(UIApplicationLaunchOptionsURLKey) as String
Run Code Online (Sandbox Code Playgroud)
但它给出了错误:
'(NSString!) - > $ T2'与'[NSObject:AnyObject]'不同
出现错误?但难以正确地投射它并且找不到如何做的链接.
UILocalNotification已被折旧,因此我想将我的代码更新为UserNotification框架:
let alertDays = 3.0
let alertSeconds = alertDays * 24.0 * 60.0 * 60.0
let localNotification:UILocalNotification = UILocalNotification()
localNotification.alertAction = "Reminder"
localNotification.alertTitle = "Reminder Title"
localNotification.alertBody = "Reminder Message"
localNotification.fireDate = Foundation.Date(timeIntervalSinceNow: alertSeconds)
localNotification.repeatInterval = .day
UIApplication.shared().scheduleLocalNotification(localNotification)
Run Code Online (Sandbox Code Playgroud)
在等待初始通知后,如何使用UserNotification框架设置类似的每日或每小时重复?
let alertDays = 3.0
let alertSeconds = alertDays * 24.0 * 60.0 * 60.0
let content: UNMutableNotificationContent = UNMutableNotificationContent()
content.title = "Reminder Title"
content.subtitle = "Reminder Subtitle"
content.body = "Reminder Message"
let calendar = Calendar.current
let alarmTime = Foundation.Date(timeIntervalSinceNow: alertSeconds)
let …Run Code Online (Sandbox Code Playgroud) 我已经创建了一个玩家可以移动的SceneKit 3D迷宫世界.像跳跃这样的一些动作涉及在几秒钟的时间段内改变观察方向时上下移动相机.在此期间,我想忽略用户的轻击和滑动,这通常会导致其他类型的动作,如转弯和前进.
我可以创建一个匹配跳转持续时间的计时器并设置Bool,但我希望能够以更简单的方式检查摄像机的SCNNode.
有没有一种简单的方法来查看相机的SCNNode是否不再运行SCNAction跳转,所以我可以在其他点按和滑动操作之前添加此逻辑?
或者也许有一个SCNAction可以设置我可以在跳转序列的开始和结束时放置的Bool?
这是我的跳转代码:
let jumpUp: SCNAction = SCNAction.move(to: SCNVector3Make(Float(Int(-yPos)), Float(Int(xPos)), jumpHeight), duration: jumpTime)
let jumpAppex: SCNAction = SCNAction.wait(duration: jumpWaitTime)
let fallDown: SCNAction = SCNAction.move(to: SCNVector3Make(Float(Int(-yPos)), Float(Int(xPos)), cameraHeight), duration: jumpTime)
var lookDown: SCNAction = SCNAction.rotateTo(x: 0, y: 0, z: CGFloat(?), duration: jumpTurnTime)
let noLook: SCNAction = SCNAction.wait(duration: jumpTime*2.0)
var lookBack: SCNAction = SCNAction.rotateTo(x: 0, y: 0, z: 0, duration: jumpTurnTime)
switch playerDirection.direction
{
case .south:
lookDown = SCNAction.rotateTo(x: 0, y: 0, z: CGFloat(southZ), duration: jumpTurnTime)
lookBack = SCNAction.rotateTo(x: …Run Code Online (Sandbox Code Playgroud) 我想为watchOS 3创建一个复杂功能,只需启动我的应用程序.我用XCode创建了ComplicationController:
class ComplicationController: NSObject, CLKComplicationDataSource
{
// MARK: - Timeline Configuration
func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {
handler([.forward, .backward])
}
func getTimelineStartDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) {
handler(nil)
}
func getTimelineEndDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) {
handler(nil)
}
func getPrivacyBehavior(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationPrivacyBehavior) -> Void) {
handler(.showOnLockScreen)
}
// MARK: - Timeline Population
func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) …Run Code Online (Sandbox Code Playgroud)