0

我有一个应用程序,其中我有一个 constants.h 类,它有一些预定义的 values.as

#define #define PUSHER_API_KEY@""
#define PUSHER_API_SECRET @""
#define PUSHER_APP_ID     @""

和一个身份验证 url #define PRESENCE_AUTH_URL @"http://hdjhjf.com/presence-auth.php?uid=11&mdid=14",其中 uid 和 mdid 我需要是动态的。所以我需要从 userdefaults 中获取它。但是在那个 constant.h 类中我如何使用它。当我尝试使用它时,它给了我一个错误initiliser 不是编译时间常数。我必须将此硬编码 11&14 更改为动态值。有人可以帮助我吗?

4

1 回答 1

0

如果您迫切希望将此作为#define声明。然后你可以这样做。

#define PRESENCE_AUTH_URL [NSString stringWithFormat:@"http://hdjhjf.com/presence-auth.php?uid=%@&mdid=%@", [[NSUserDefaults standardUserDefaults] objectForKey:@"UDIDKey"], [[NSUserDefaults standardUserDefaults] objectForKey:@"MDIDKey"]]

看起来您正在使用 libPusher,您也可以通过这种方式设置 auth url。

pusher.authorizationURL = [NSString stringWithFormat:@"http://hdjhjf.com/presence-auth.php?uid=%@&mdid=%@", [[NSUserDefaults standardUserDefaults] objectForKey:@"UDIDKey"], [[NSUserDefaults standardUserDefaults] objectForKey:@"MDIDKey"]];
于 2013-01-25T09:47:18.957 回答