小编cds*_*oft的帖子

收到iOS推送通知时打开视图控制器

我想在用户点击收到的推送通知消息时打开特定的视图控制器,但是当我收到推送通知消息并单击该消息时,只打开应用程序,但它不会重定向到特定的视图控制器.

我的代码是

-(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推送通知有关.

cocoa-touch push-notification ios appdelegate

28
推荐指数
2
解决办法
4万
查看次数

推送通知-didFinishLaunchingWithOptions

当我发送推送通知并且我的应用程序处于打开状态或后台并且我点击推送通知时,我的应用程序重定向到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)

cocoa-touch storyboard push-notification ios

14
推荐指数
3
解决办法
2万
查看次数

Xcode 4和xcode 5在一起

我可以将Xcode 5和Ios 7 Beta与xcode 4一起安装吗?

我有xcode 4,我可以用Ios 7安装xcode 5,在ios 6上使用xcode 4开发的项目是否有任何问题.

xcode4 ios7 xcode5

3
推荐指数
1
解决办法
6734
查看次数

Iphone应该在键盘上阻止0号码

我一直在用xcode编写iphone应用程序,有一个包含电话号码字段的表单.它必须包含10位数字.如果用户首先在键盘中按0,则应用程序不得写入.

例如,电话号码05551234567,用户只能写5551234567.如果用户按0,则没有任何反应.

iphone keyboard xcode objective-c

0
推荐指数
1
解决办法
79
查看次数