在Swift AppDelegate类中,您将获得以下方法:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// ...code...
return true
}
launchOptions: [NSObject: AnyObject]?
参数是可选的。在Objective-C中,这是作为NSDictionary
传递的。我想从中提取UIApplicationLaunchOptionsRemoteNotificationKey
。以下是在Objective-C中完成的工作:
NSDictionary *remoteNotification = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
if (remoteNotification)
{
// ...do stuff...
}
你会如何在Swift中做到这一点?
答案 0 :(得分:27)
在Swift中,你会这样做:
if let remoteNotification = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary {
// ...do stuff...
}
答案 1 :(得分:1)
我在Swift中处理它:
using (var receiver = new PullSocket())
{
receiver.Bind("tcp://localhost:5557");
while (true)
{
var payload = receiver.ReceiveFrameString();
log.Debug($"Payload: {payload}");
}
}
答案 2 :(得分:0)
我认为对于Swift 3,它会是这样的:
if (launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? NSDictionary) != nil {
// ...do stuff
}