2014-01-09 111 views
2

只需要確認。如果我使用了靜默推送通知服務(如用於詢問何時使用推送通知),應用程序是否會請求用戶權限?任何幫助,將不勝感激無聲推送通知

+1

是的,它會要求確保 – Retro

+0

你可以發送關於它的任何教程鏈接。 – Avinash

+2

看這裏http://hayageek.com/ios-silent-push-notifications/並檢查WWDC vedios – Retro

回答

2

不,這是沉默的,這意味着它在後臺工作,沒有用戶確認在通知時。

在應用程序安裝時,它要求確認,如正常的推送通知。

+0

我的意思是在應用程序安裝過程中。它是否要求用戶許可? – Avinash

+0

是的。我編輯了我的答案。 – Vrasidas

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); 
}