如何从AppDelegate打印NSLog?

时间:2015-11-18 20:26:18

标签: swift token appdelegate

我只是想看看我的令牌设备。

这就是我的所作所为:

while($table = mysqli_fetch_array($result)) {
        echo '<a href="yourPath/'. $student_courses[0] . '">' . 
     $student_courses[0] . '</a>';
          }

但是func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { let pushSettings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes:[UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound],categories: nil) UIApplication.sharedApplication().registerUserNotificationSettings(pushSettings) UIApplication.sharedApplication().registerForRemoteNotifications() return true } // Successfully registered for push func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { let trimEnds = deviceToken.description.stringByTrimmingCharactersInSet(NSCharacterSet(charactersInString: "<>")) let cleanToken = trimEnds.stringByReplacingOccurrencesOfString(" ", withString: "", options: []); print(cleanToken) //registerTokenOnServer(cleanToken) //theoretical method! Needs your own implementation } // Failed to register for Push func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) { NSLog("Failed to get token; error: %@", error) //Log an error for debugging purposes, user doesn't need to know } 什么也没做。我不知道我是否可以在AppDelegate中使用print(cleanToken)。我还创建了一个全局变量,并将print保存到该新变量中。然后我在我的viewController中打印它,但它是空的。

2 个答案:

答案 0 :(得分:1)

你是否可以在模拟器中运行它?然后你可能不会在didRegisterForRemoteNotificationsWithDeviceToken接到电话。你需要在实际的手机上运行它

答案 1 :(得分:0)

固定。我只是通知我的应用程序停用了sos代码不起作用。我已经卸载了应用程序并再次安装它,因此它运行正常。