I've been searching for hours now and can't find the solution to my problem: I am sending a pushnotification to my app with this php script: http://pastebin.com/9axHdM0t. With it I send additional Information: 'patient' => 'test'
. Now I wanted to extract this Information and set a Label to it. I am doing this with this function in the AppDelegate:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject])
{
//extracting the information
let info = userInfo["aps"] as! Dictionary<String, AnyObject>
let pat = info["patient"] as! String
//print(pat) works fine
//sending the variable to the viewcontroller and triggering the function wich sets the text of the Label
vc.patientx = pat
vc.settext(vc.patientx)
}
In my Viewcontroller, I'm doing this:
@IBOutlet var patientxy: UITextField!
var patientx:String!
func settext(name: String)
{
if patientx != nil {
//print(patientx) works fine.
patientxy.text = patientx
AudioServicesPlaySystemSound(1304)
AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
}
}
Printing the variable works fine and then setting the label to the var makes the code crash:
fatal error: unexpectedly found nil while unwrapping an Optional value.
What is the problem? This is my AppDelegate: http://pastebin.com/mXC0wL5E and my Viewcontroller: http://pastebin.com/45dTVLZ3.
I've tried many suggested solutions (many from Stack Overflow) like check if the Label is still connected or update the label in a different way, but I can't find a working solution.