无声推送通知

时间:2014-01-09 07:08:18

标签: ios iphone apple-push-notifications

只是想要确认。如果我使用了静音推送通知服务(例如,它用于询问何时使用推送通知),那么应用是否会请求用户权限。任何帮助将不胜感激

2 个答案:

答案 0 :(得分:2)

没有。它是静音的,这意味着它在后台运行,在通知时没有用户确认。

在应用安装时,它会像正常推送通知一样要求确认。

答案 1 :(得分:0)

对于静音推送,你必须像这样设置JSON(php文件),

$body['aps'] = array(
    'sound' => '',
    'content-available' => 1
    );

不要发送提醒和徽章。

在xcode文件中选择目标 - >功能和启用后台模式并勾选远程通知

在appdelegate.m文件中的

只是使用此消息来接收静默推送

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
{
    //Success this method will automatically call when device receives push notification
    handler(UIBackgroundFetchResultNewData);
}

// eg code to register for apps
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge
                                                                                             |UIRemoteNotificationTypeSound
                                                                                             |UIRemoteNotificationTypeAlert) categories:nil];
        [application registerUserNotificationSettings:settings];
    } else {
        UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
        [application registerForRemoteNotificationTypes:myTypes];
    }

    return YES;
}


#ifdef __IPHONE_8_0
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    //register to receive notifications
    [application registerForRemoteNotifications];
}

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler
{
    //handle the actions
    if ([identifier isEqualToString:@"declineAction"]){
    }
    else if ([identifier isEqualToString:@"answerAction"]){
    }
}
#endif

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
    NSLog(@"My token is: %@", deviceToken);
}

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
    NSLog(@"Failed to get token, error: %@", error);
}