苏打熊 2015-08-18 06:39 采纳率: 64.3%
浏览 1778

AppDelegate.m中的局部产量在viewcontroller.m中如何调用?

  • (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
    {
    // 打印到日志 textView 中
    [self.viewController addLogString:[NSString stringWithFormat:@"backgroud : %@",userInfo]];

    completionHandler(UIBackgroundFetchResultNewData);

}
以上代码为AppDelegate.m中的userInfo .这个userInfo是不是局部产量?我需要在viewcontroller.m中调用它,比如说把它拼接到字符串里面,我该使用什么方法呢?

  • 写回答

1条回答 默认 最新

  • ruzhuxiaogu 2015-08-18 13:24
    关注

    使用NSNotificationCenter
    1.首先,在viewcontroller.m中注册通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getDict:) name:@"test" object:nil];
    并且定义通知触发之后的动作getString函数

    • (void)getDict:(NSNotification*)notification{ NSDictionary *dict=[notification object]; NSLog(@"userInfo:%@",dict); //对传过来的值进行操作 }

    2.在AppDelegate.m中触发通知

    (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
    {
    // 打印到日志 textView 中
    [self.viewController addLogString:[NSString stringWithFormat:@"backgroud : %@",userInfo]];
    //触发通知
    [[NSNotificationCenter defaultCenter] postNotificationName:@"test" object:userInfo];
    completionHandler(UIBackgroundFetchResultNewData);
    }
    你试试,不行的话再找我。

    评论

报告相同问题?

悬赏问题

  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?