我想更改从推送通知打开应用程序时打开的选项卡。
目前,我让应用程序在应用程序委托(delegate)中注册通知并在第一个 View Controller 中运行一个方法:
AppDelegate.m
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"didReceiveRemoteNotification");self.apstype = [[NSMutableString alloc] init];self.apstype = [NSMutableString stringWithFormat:@"%@", [[userInfo objectForKey:@"aps"] objectForKey:@"apstype"]];
// Add the tab bar controller's current view as a subview of the window
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
HomeTab_Main *controller = [HomeTab_Main alloc];
[controller receivedNotification];
if (application.applicationState == UIApplicationStateActive){
NSLog(@"UIApplicationStateActive");
} else if (application.applicationState == UIApplicationStateBackground){
NSLog(@"UIApplicationStateBackground");
} else if (application.applicationState == UIApplicationStateInactive){
NSLog(@"UIApplicationStateInactive");
} else {
NSLog(@"else");
}
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UINavigationBar *navigationBarProxy = [UINavigationBar appearance];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
UIImage *backgroundImage = [UIImage imageNamed:@"ge_navigationBar.png"];
[navigationBarProxy setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
UIImage *backgroundImage = [UIImage imageNamed:@"ge_navigationBar~ipad.png"];
[navigationBarProxy setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
}
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
UIColor *tintColour = [UIColor colorWithRed:0.000 green:0.600 blue:0.765 alpha:1];
[[UIBarButtonItem appearance] setTintColor:tintColour];
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
UITextAttributeTextColor, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset, [UIFont fontWithName:@"Arial-Bold" size:0.0], UITextAttributeFont, nil]];
return YES;
}
HomeTab_Main.m
- (void)receivedNotification
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSLog(@"%@", appDelegate.apstype);
if([appDelegate.apstype isEqualToString:@"inbox"]){
NSLog(@"goToTab");
[self performSelector:@selector(goToTab) withObject:nil afterDelay:0.1];
}
}
- (void)goToTab
{
NSLog(@"Go to tab");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"1 new message" message:@"click to read" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:nil, nil];
[alert show];
self.tabBarController.selectedIndex = 2;
}
我遇到的主要问题是警报 View 正在显示,但选项卡没有改变。 从通知访问应用程序时,我想自动切换到相应的选项卡。有谁知道这如何通过任何示例实现?
添加了 didFinishLaunchingWithOptions
最佳答案
Luc 是对的,尽管它是 self.view.window.rootViewController 而不是 self.rootviewcontroller。
但是我不认为这是完美的解决方案,因为 TabBarController 并不总是必须是 rootViewController...
您的 TabBarController 是否在应用委托(delegate)/主窗口或另一个 viewController 中?
尝试在应用委托(delegate)或持有 TabBarController 的 viewController 中设置 selectedIndex。
我使用它在我的一个应用程序中使用它:
AppDelegate.m
-(void)showReportTab{
[self.tabBarController setSelectedIndex:1];
}
AppDelegate.h
@property (nonatomic, strong) IBOutlet UITabBarController *tabBarController;
关于iphone - 收到推送通知后更改选定的选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11154289/
如何正确创建Rails迁移,以便将表更改为MySQL中的MyISAM?目前是InnoDB。运行原始执行语句会更改表,但它不会更新db/schema.rb,因此当在测试环境中重新创建表时,它会返回到InnoDB并且我的全文搜索失败。我如何着手更改/添加迁移,以便将现有表修改为MyISAM并更新schema.rb,以便我的数据库和相应的测试数据库得到相应更新? 最佳答案 我没有找到执行此操作的好方法。您可以像有人建议的那样更改您的schema.rb,然后运行:rakedb:schema:load,但是,这将覆盖您的数据。我的做法是(假设
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘
我尝试使用不同的ssh_options在同一阶段运行capistranov.3任务。我的production.rb说:set:stage,:productionset:user,'deploy'set:ssh_options,{user:'deploy'}通过此配置,capistrano与用户deploy连接,这对于其余的任务是正确的。但是我需要将它连接到服务器中配置良好的an_other_user以完成一项特定任务。然后我的食谱说:...taskswithoriginaluser...task:my_task_with_an_other_userdoset:user,'an_othe
假设我有一个FireNinja我的数据库中的对象,使用单表继承存储。后来才知道他真的是WaterNinja.将他更改为不同的子类的最干净的方法是什么?更好的是,我很想创建一个新的WaterNinja对象并替换旧的FireNinja在数据库中,保留ID。编辑我知道如何创建新的WaterNinja来self现有FireNinja的对象,我也知道我可以删除旧的并保存新的。我想做的是改变现有项目的类别。我是通过创建一个新对象并执行一些ActiveRecord魔法来替换行,还是通过对对象本身做一些疯狂的事情,或者甚至通过删除它并使用相同的ID重新插入来做到这一点,这是问题的一部分。
简而言之错误:NOTE:Gem::SourceIndex#add_specisdeprecated,useSpecification.add_spec.Itwillberemovedonorafter2011-11-01.Gem::SourceIndex#add_speccalledfrom/opt/local/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:91./opt/local/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/rails/gem_dependency.rb:275:in`==':und
有人知道在发布新版本的Ruby和Rails时收到电子邮件的方法吗?他们有邮件列表,RubyonRails有一个推特,但我不想听到那些随之而来的喧嚣,我只想知道什么时候发布新版本,尤其是那些有安全修复的版本。 最佳答案 从therailsblog获取提要.http://weblog.rubyonrails.org/feed/atom.xml 关于ruby-on-rails-如何在发布新的Ruby或Rails版本时收到通知?,我们在StackOverflow上找到一个类似的问题:
我想解析一个已经存在的.mid文件,改变它的乐器,例如从“acousticgrandpiano”到“violin”,然后将它保存回去或作为另一个.mid文件。根据我在文档中看到的内容,该乐器通过program_change或patch_change指令进行了更改,但我找不到任何在已经存在的MIDI文件中执行此操作的库.他们似乎都只支持从头开始创建的MIDI文件。 最佳答案 MIDIpackage会为您完成此操作,但具体方法取决于midi文件的原始内容。一个MIDI文件由一个或多个音轨组成,每个音轨是十六个channel中任何一个上的
我最喜欢的Google文档功能之一是它会在我工作时不断自动保存我的文档版本。这意味着即使我在进行关键更改之前忘记在某个点进行保存,也很有可能会自动创建一个保存点。至少,我可以将文档恢复到错误更改之前的状态,并从该点继续工作。对于在MacOS(或UNIX)上运行的Ruby编码器,是否有具有等效功能的工具?例如,一个工具会每隔几分钟自动将Gitcheckin我的本地存储库以获取我正在处理的文件。也许我有点偏执,但这点小保险可以让我在日常工作中安心。 最佳答案 虚拟机有些人可能讨厌我对此的回应,但我在编码时经常使用VIM,它具有自动保存功
我想在IRB中浏览文件系统并让提示更改以反射(reflect)当前工作目录,但我不知道如何在每个命令后进行提示更新。最终,我想在日常工作中更多地使用IRB,让bash溜走。我在我的.irbrc中试过这个:require'fileutils'includeFileUtilsIRB.conf[:PROMPT][:CUSTOM]={:PROMPT_N=>"\e[1m:\e[m",:PROMPT_I=>"\e[1m#{pwd}>\e[m",:PROMPT_S=>"FOO",:PROMPT_C=>"\e[1m#{pwd}>\e[m",:RETURN=>""}IRB.conf[:PROMPT_MO