Swift read userInfo of remote notification

后端 未结 7 1614
庸人自扰
庸人自扰 2020-12-08 02:11

I implemented a function to open an AlertView when I receive a remote notification like this:

func application(application: UIApplication, didReceiveRemoteNo         


        
7条回答
  •  不思量自难忘°
    2020-12-08 02:57

    This is my version for objC

    if (userInfo[@"aps"]){
        NSDictionary *aps = userInfo[@"aps"];
        if (aps[@"alert"]){
            NSObject *alert = aps[@"alert"];
            if ([alert isKindOfClass:[NSDictionary class]]){
                NSDictionary *alertDict = aps[@"alert"];
                if (alertDict[@"message"]){
                    NSString *message = alertDict[@"message"];
                }
            }
            else if (aps[@"alert"]){
                NSString *alert = aps[@"alert"];
            }
        }
    }
    

提交回复
热议问题