【发布时间】:2016-04-12 09:36:31
【问题描述】:
当我在AppDelegate 中使用变量,然后在函数中使用它时,变量不会改变它的值!
有什么帮助吗?我使用目标c
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
// Show alert for push notifications recevied while the
// app is running
NSString *message = [[userInfo objectForKey:@"aps"]
objectForKey:@"alert"];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@""
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
如何在此函数之外获取消息?
【问题讨论】:
-
您是否考虑过将消息存储在 SharedPreferences 中,以便在不引用 AppDelegate 的情况下在任何地方检索它?这可能是比引用和强制转换 AppDelegate 更清洁的解决方案。
-
在外部函数中声明变量
-
Martino Lessio 我该怎么做?我想在 appdelegate 中使用它而不是其他视图控制器
标签: objective-c variables appdelegate