我想在用户点击收到的推送通知消息时打开特定的视图控制器,但是当我收到推送通知消息并单击该消息时,只打开应用程序,但它不会重定向到特定的视图控制器.
我的代码是
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if (applicationIsActive) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Bildirim"
message:[NSString stringWithFormat:@"%@ ",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]]
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
UIViewController *vc = self.window.rootViewController;
PushBildirimlerim *pvc = [vc.storyboard instantiateViewControllerWithIdentifier:@"PushBildirimlerim "];
[vc presentViewController:pvc animated:YES completion:nil];
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题与iOS推送通知有关.
当我发送推送通知并且我的应用程序处于打开状态或后台并且我点击推送通知时,我的应用程序重定向到PushMessagesVc
viewController
(按预期)
我使用下面的代码:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
PushMessagesVc *pvc = [mainstoryboard instantiateViewControllerWithIdentifier:@"PushMessagesVc"];
[self.window.rootViewController presentViewController:pvc
animated:YES
completion:NULL];
}
Run Code Online (Sandbox Code Playgroud)
上面的代码/方案没有问题,但如果应用程序关闭并且我点击推送通知,则PushMessagesVc
viewController
在这种情况下应用程序不会重定向我的应用程序停留在主屏幕上.
对于第二种情况,我使用以下代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
sleep(1);
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeNone)];
[UIApplication sharedApplication].applicationIconBadgeNumber = 1;
NSDictionary *userInfo = [launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
if(apsInfo) {
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
PushMessagesVc* pvc = [mainstoryboard instantiateViewControllerWithIdentifier:@"PushMessagesVc"];
[self.window.rootViewController presentViewController:pvc animated:YES completion:NULL];
return YES; …
Run Code Online (Sandbox Code Playgroud) 我可以将Xcode 5和Ios 7 Beta与xcode 4一起安装吗?
我有xcode 4,我可以用Ios 7安装xcode 5,在ios 6上使用xcode 4开发的项目是否有任何问题.
我一直在用xcode编写iphone应用程序,有一个包含电话号码字段的表单.它必须包含10位数字.如果用户首先在键盘中按0,则应用程序不得写入.
例如,电话号码05551234567,用户只能写5551234567.如果用户按0,则没有任何反应.
cocoa-touch ×2
ios ×2
appdelegate ×1
ios7 ×1
iphone ×1
keyboard ×1
objective-c ×1
storyboard ×1
xcode ×1
xcode4 ×1
xcode5 ×1