簡體   English   中英

找出用戶在iOS顯示的UIAlertView上選擇的按鈕的方式,請求允許該應用接收推送通知的權限

[英]Way to find out which button the user selected on the UIAlertView displayed by iOS ,asking permission to allow the app to receive push notification

有沒有辦法與iOS的警報顯示進行交互。例如:如果我的應用程序已經注冊了自己的APNS,在首次啟動時,iOS顯示UIAlertView(我假設,它是一個),給用戶兩個選擇.Is有辦法找出用戶選擇的按鈕嗎? 我在應用程序啟動期間顯示了兩個警報,一個用於APNS,另一個用於位置服務。有沒有辦法確定哪個警報用於什么?

沒有。無法在操作系統創建的AlertViews上獲得回調。 就像CoolMonster在他的評論中指出的那樣,你可以找出用戶為特定的AlertView選擇了什么,並根據它做了一些事情。

如果您無法直接訪問這些警報,我建議您從另一個角度來看這個問題。

例如,對於CoreLocation,您可以查看其[CLLocationManager authorizationStatus]

   kCLAuthorizationStatusNotDetermined = 0, // User wasn't proposed to use location services
   kCLAuthorizationStatusRestricted, // Parental control or something like that
   kCLAuthorizationStatusDenied,    // User didn't allow this application to use services
   kCLAuthorizationStatusAuthorized // User allowed to use his location.

至於APNS,有[[UIApplication sharedApplication] enabledRemoteNotificationTypes]

資料來源: https//developer.apple.com/library/ios/documentation/uikit/reference/UIApplication_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UIRemoteNotificationType

https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/doc/c_ref/CLAuthorizationStatus

我不知道推送通知,但這是一種(丑陋的)方式,在要求獲取用戶位置的權限時檢測用戶的選擇:

// After asking for permission, the alert is shown to the user. Since he can't do anything
// at this point but select one of the two options we simply wait...
while(([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined))
{
     sleep(1);
}
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized)
{
    NSLog(@"User allowed access to gps");
}
else
{
    NSLog(@"User denied access to gps");
}

您可以獲得如下通知類型:

UIRemoteNotificationType notificationTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

並且可能會創建一些黑客方法來讓用戶與通知問題進行交互

雖然可能沒有明確的方法來了解用戶點擊的按鈕,但您可以通過實現這些UIApplication委托方法來確定用戶是否授權使用推送通知:

application:didRegisterForRemoteNotificationsWithDeviceToken :(用戶接受)

application:didFailToRegisterForRemoteNotificationsWithError :(用戶被拒絕或無法接受)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM