启用通知

时间:2012-12-14 07:59:12

标签: iphone xcode4 push-notification apple-push-notifications

我想在我的iphone应用中启用通知。所以,我在应用ID中修改:

enter image description here

之后,我再次生成开发和分发配置文件并安装在我的xcode中。

我的应用是基于标签的应用,第一个标签是UITableViewController

我添加以下行:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];

   return YES;
}

所以,我想我应该将我的应用程序放在我的iphone中安装了通知的应用程序列表中,但它不是。

我是否错过了一些步骤?

2 个答案:

答案 0 :(得分:2)

首先在app delegate中启用远程通知。见下文:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];

    // Let the device know we want to receive push notifications
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
        (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

    return YES;
}

答案 1 :(得分:2)

是的。根据{{​​3}}和this,您应该在registerForRemoteNotificationTypes中添加didFinishLaunchingWithOptions方法,该方法应如下所示:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];

    return YES;
}

根据您注册的类型,您的应用将显示在通知部分,您可以打开和关闭不同的类型(声音,徽章,横幅)。

希望有所帮助。