苏打熊 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 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献