简体   繁体   English

为什么我的ios应用不会提示我许可推送通知

[英]Why my ios app not prompt me for permission to push notifications

i am new to ios and i am working on ios push notifications,I have successfully implemented the code and getting notification,But only thing is my app not asking me for permission,As other apps are giving a prompt for asking permission for push notifications,I have gone through some links as below,Which i cant understood,my code is as below can anybody please tell me what changes i should make to prompt this permission alert?thanks in advance. 我是ios的新手,我正在研究ios推送通知,我已经成功实现了代码并获得了通知,但唯一的问题是我的应用程序未向我征求许可,因为其他应用程序提示输入征求对推送通知的许可,我已经浏览了以下某些链接,我无法理解,我的代码如下,任何人都可以告诉我为提示此权限警报而应进行哪些更改吗?谢谢。 App not asking for permission for push 应用程序未请求允许推送

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    isAppLaunched=YES;
    [application setStatusBarHidden:NO];

    [Fabric with:@[[Crashlytics class]]];

    [NSThread sleepForTimeInterval:3.0];

    NSUserDefaults *st = [NSUserDefaults standardUserDefaults];
    //
    //    [st removeObjectForKey:@"temp_lat_flag"];
    //    [st removeObjectForKey:@"temp_lon_flag"];
    //
    //    [st removeObjectForKey:@"temp_lat_flag1"];
    //    [st removeObjectForKey:@"temp_lon_flag1"];
    //
    //    [st removeObjectForKey:@"temp_lat_flag2"];
    //    [st removeObjectForKey:@"temp_lon_flag2"];
    //
    //    [st removeObjectForKey:@"temp_lat_flag3"];
    //    [st removeObjectForKey:@"temp_lon_flag3"];
    //
    //    [st synchronize];

    /*  self.sk=[SKDatabase alloc];
     NSArray *paths = NSSearchPathForDirectoriesInDomains( NSCachesDirectory,
     NSUserDomainMask, YES);

     NSString *documentsDirectory = [paths objectAtIndex:0];

     self.sk.queryFilePath=[documentsDirectory stringByAppendingPathComponent:@"query.txt"];
     NSData *strData=[NSData  dataWithContentsOfFile:self.sk.queryFilePath];
     NSString *str=[NSString stringWithUTF8String:[strData bytes]];
     NSArray *arr=[[NSArray alloc] initWithArray:[str componentsSeparatedByString:@";~"]];
     NSLog(@"%d",[arr count]);
     for(NSString *sql in arr)
     {
     [app.sk runDynamicSQLQuery:sql];
     }*/
    [application setStatusBarStyle:UIStatusBarStyleLightContent];

    commonWebServiceUrl = @"http://www.explorecayman.com/";
    // commonWebServiceUrl = @"http://192.168.X.3/abcd/";
    // commonWebServiceUrl = @"http://www.xyzd.com/beta/";

    self.willResignActive = NO;

    updateData = 1;

    //    app = (iPhoneECAppDelegate *)[[UIApplication sharedApplication] delegate];

    showOfflinePopup = 0;

    internetConnection = 1;
    /* Internet checking  */
    [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];

    Reachability *reach = [Reachability reachabilityForInternetConnection];
    reach.reachableOnWWAN =  YES;
    reach.reachableBlock = ^(Reachability * reachability)
    {
        NSLog(@"Block Says Reachable :: %d",self.internetConnection);
        self.internetConnection = 1;
    };
    reach.unreachableBlock = ^(Reachability * reachability)
    {
        NSLog(@"Block Says UNreachable");
        self.internetConnection = 0;
    };
    [reach startNotifier];

    if (self.successPhotoArray == Nil)
    {
        self.successPhotoArray = [[NSMutableArray alloc] init];
    }

    //        [self CheckInternetConnectionByHostName:timer];

    [self startTimerInBackground_noBackground];

    backgroundOrNot = NO;

    //Add Google Analytics
    NSDictionary *appDefaults = @{kAllowTracking: @(YES)};
    [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
    [GAI sharedInstance].optOut =
    ![[NSUserDefaults standardUserDefaults] boolForKey:kAllowTracking];
    [GAI sharedInstance].dispatchInterval = 120;
    [GAI sharedInstance].trackUncaughtExceptions = NO;
    self.tracker = [[GAI sharedInstance] trackerWithName:@"ECiPhone"
                                              trackingId:kTrackingId];
    [[GAI sharedInstance].logger setLogLevel:kGAILogLevelVerbose];

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    searchFlag = FALSE;
    historyFlag = FALSE;
    favouriteFlag = FALSE;
    mapFlag = FALSE;
    searchStr = @"";
    appStartDownloadFlag = 0 ;

    self.HomeOrNot = 0;
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
    locationManager.distanceFilter = 30.0;
    deviceVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
    [self.locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    //    if(version >= 6.0)
    //    {
    //        deviceVersion = 6;
    //    }
    //    else
    //    {
    //        deviceVersion = 5;
    //    }


//    if(deviceVersion>=8.0)
//    {
//        UIUserNotificationType types =  UIUserNotificationTypeSound |UIUserNotificationTypeAlert;
//        UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
//        [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
//        
//        [self.locationManager requestWhenInUseAuthorization];
//        
//    }

    if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
    {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
        [self.locationManager requestWhenInUseAuthorization];
    }
    else
    {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
         (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
        [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
        [self.locationManager startUpdatingLocation];
    }


    if(![st objectForKey:@"appStartFlag"])
    {
        [st setValue:[NSNumber numberWithInt:0] forKey:@"appStartFlag"];
        [st synchronize];
    }
    [st setValue:[NSNumber numberWithFloat:0.000000] forKey:@"Photo_DataDownload"];
    [st synchronize];

    NSUserDefaults *st1= [NSUserDefaults standardUserDefaults];
    if (![st1 objectForKey:@"updatedDatabaseDate"])
    {
        [st1 setObject:@"2010-01-01 00:00:00" forKey:@"updatedDatabaseDate"];
        [st1 synchronize];
    }
    if (![st1 objectForKey:@"updatedEventDate"])
    {
        [st1 setObject:@"2010-01-01 00:00:00" forKey:@"updatedEventDate"];
        [st1 synchronize];
    }
    if (![st1 objectForKey:@"updatedTagDate"])
    {
        [st1 setObject:@"2010-01-01 00:00:00" forKey:@"updatedTagDate"];
        [st1 synchronize];
    }
    if (![st1 objectForKey:@"updatedPhotoDate"])
    {
        [st1 setObject:@"2010-01-01 00:00:00" forKey:@"updatedPhotoDate"];
        [st1 synchronize];
    }
    if (![st1 objectForKey:@"updatedEventPhotoDate"])
    {
        [st1 setObject:@"2010-01-01 00:00:00" forKey:@"updatedEventPhotoDate"];
        [st1 synchronize];
    }
    if(![st1 objectForKey:@"StartedRefresh"])
    {
        [st1 setObject:[NSNumber numberWithInt:0] forKey:@"StartedRefresh"];
        [st1 synchronize];
    }

    localTimeZone = [NSTimeZone systemTimeZone];

    if (internetConnection == 1)
    {
        [self getrate];
        [self getKYDrate];

        [self performSelectorInBackground:@selector(HitDataSend) withObject:nil];
        [self performSelectorInBackground:@selector(reviewDataSend) withObject:nil];
        [self performSelectorInBackground:@selector(enquiryDataSend) withObject:nil];
        [self performSelectorInBackground:@selector(reservationDataSend) withObject:nil];
    }
    else
    {
        kydRate = 1.00f;
        NSUserDefaults *st = [NSUserDefaults standardUserDefaults];
        if ([st objectForKey:@"currencyRate"])
        {
            NSArray *Arr = [st objectForKey:@"currencyRate"];
            if ([[[Arr objectAtIndex:0] objectForKey:@"rate"] floatValue] == 0.00)
            {
                rate = 1;
            }
            else
            {
                rate = [[[Arr objectAtIndex:0] objectForKey:@"rate"] floatValue];
            }
        }
    }

    /** Apple push notification **/
//    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
//    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;

    RoundedValue_list   = 10;
    RoundedValue_menu   = 100;
    RoundedValue_detail = 1000;
    //---------------
    additionalQuery = [[NSString alloc] initWithFormat:@"AND chr_publish='Y' AND chr_delete='N'"];
    deleteQuery = [[NSString alloc] initWithFormat:@"AND chr_delete='N'"];

    if (![st1 objectForKey:@"EventUpdate"])
    {
        [st1 setObject:[NSDate date] forKey:@"EventUpdate"];
        [st1 synchronize];
    }
    if (![st1 objectForKey:@"DataUpdate"])
    {
        [st1 setObject:[NSDate date] forKey:@"DataUpdate"];
        [st1 synchronize];
    }


    self.isReloadTable = YES;
    menuOrderno=[[NSMutableDictionary alloc]init];
    noInternetPage=0;
    rate = 1.25;
    currencySign = @"$";
    currencySel = @"USD";
    orient = [UIApplication sharedApplication].statusBarOrientation;
    refreshCompletedFlag = 0;
    dRefreshCompleted=0;
    eRefreshCompleted = 0;
    pRefreshCompleted=0;
    homeReachFlag = 0;
    ValSortBy=@"";
    ValFilterBy = @"";
    ValCategory=@"";
    ValArea=@"";
    catSelectedVal=@"";
    hitFlag=0;
    addEnqFlag = 0;
    homeFromDetailFlag=0;
    selectedCat = 0;
    appBGFlag=60;
    startTagQuery = 0;
    startDbQuery=0;
    reservationFlag=0;
    reviewFlag = 0;
    favSyncFlag = 0;
    self.loginWithFbFlag = 0;
    self.downloadRefresh = 0;

//    if ([st objectForKey:@"appCounter"])
//    {
//        int counter = [[st objectForKey:@"appCounter"] intValue];
//        counter = counter + 1;
//        [st setObject:[NSString stringWithFormat:@"%d",counter] forKey:@"appCounter"];
//        [st synchronize];
//        
//        //Replace with 10 and 25
//        if ([[st objectForKey:@"appCounter"] isEqualToString:@"10"])
//        {
//            [Appirater appLaunched:YES];
//        }
//        else if ([[st objectForKey:@"appCounter"] isEqualToString:@"25"])
//        {
//            [Appirater appLaunched:YES];
//        }
//    }
//    else
//    {
//        [st setObject:@"1" forKey:@"appCounter"];
//        [st synchronize];
//    }



    //    if ([st objectForKey:@"appCounter"])
    //    {
    //        int counter = [[st objectForKey:@"appCounter"] intValue];
    //        counter = counter + 1;
    //        [st setObject:[NSString stringWithFormat:@"%d",counter] forKey:@"appCounter"];
    //        [st synchronize];
    //
    //        //Replace with 10 and 25
    //        if ([[st objectForKey:@"appCounter"] isEqualToString:@"10"])
    //        {
    //            [Appirater appLaunched:YES];
    //        }
    //        else if ([[st objectForKey:@"appCounter"] isEqualToString:@"25"])
    //        {
    //            [Appirater appLaunched:YES];
    //        }
    //    }
    //    else
    //    {
    //        [st setObject:@"1" forKey:@"appCounter"];
    //        [st synchronize];
    //    }


    if ([st objectForKey:@"appCounter"])
    {
        if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"appCounter"] isKindOfClass:[NSString class]]) {
            [st setObject:[NSDate date] forKey:@"appCounter"];
            [st synchronize];
        }
        int check = [self dateChangeForEventUpdate:[[NSUserDefaults standardUserDefaults]objectForKey:@"appCounter"] newDate:[NSDate date]];
        if (check >= 3)
        {
            [st setObject:[NSDate date] forKey:@"appCounter"];
            [st synchronize];

            [Appirater appLaunched:YES];
        }
    }
    else
    {
        [st setObject:[NSDate date] forKey:@"appCounter"];
        [st synchronize];
    }


    //    [self.locationManager setDistanceFilter:kCLDistanceFilterNone];


//        [self CheckInternetConnectionByHostNameOnMainThread:180];

    [self startTimerInBackground_noBackground];

    UINavigationController *navCntrl1;
    if([st1 objectForKey:@"updatedDatabaseDate"])
    {
        NSString *dbDate = [NSString stringWithFormat:@"%@", [st1 objectForKey:@"updatedDatabaseDate"]];
        NSString *version_date = [NSString stringWithFormat:@"%@",[st1 objectForKey:@"version_date"]];
        NSString *photodate = [NSString stringWithFormat:@"%@",[st1 objectForKey:@"updatedPhotoDate"]];

        if(([dbDate isEqualToString:@"2010-01-01 00:00:00"] || [dbDate isEqualToString:version_date]) || [photodate isEqualToString:@"2010-01-01 00:00:00"])
        {
            if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"StartedRefresh"] intValue] == 1)
            {
                [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:0] forKey:@"StartedRefresh"];
                [[NSUserDefaults standardUserDefaults] synchronize];
            }

            self.viewController = [[iPhoneECDataDownload alloc] initWithNibName:@"iPhoneECDataDownload" bundle:nil];
            navCntrl1 = [[UINavigationController alloc] initWithRootViewController:self.viewController];
        }
        else
        {
            self.viewController1 = [[iPhoneECHome alloc] initWithNibName:@"iPhoneECHome" bundle:nil];
            navCntrl1 = [[UINavigationController alloc] initWithRootViewController:self.viewController1];
        }
    }

    //    self.viewController1 = [[iPhoneECHome alloc] initWithNibName:@"iPhoneECHome" bundle:nil];
    //    navCntrl1 = [[UINavigationController alloc] initWithRootViewController:self.viewController1];

    if ([navCntrl1.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] )
    {
        UIImage *image = [UIImage imageNamed:@"top-bg-portrait.png"];
        [navCntrl1.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    }
    [self setNavController:navCntrl1];

    if ([[UIDevice currentDevice].systemVersion floatValue] < 6.0)
    {
        //how the view was configured before IOS6
        [self.window addSubview: navCntrl1.view];
        [self.window makeKeyAndVisible];
    }
    else
    {
        //this is the code that will start the interface to rotate once again
        [self.window setRootViewController: navCntrl1];
        [self.window makeKeyAndVisible];
    }
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSFileManager *fileManager=[NSFileManager defaultManager];

    for(int i=1;i<=7;i++)
    {
        NSString *filePath=[documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"image%d.png",i]];
        if(![fileManager fileExistsAtPath:filePath])
        {
            [fileManager createFileAtPath:filePath contents:nil attributes:[NSDictionary dictionaryWithObject:NSFileProtectionNone forKey:NSFileProtectionKey]];
        }
    }
    /*  NSFileManager *fileMgr=[NSFileManager defaultManager];
     NSArray *fileArr=[fileMgr contentsOfDirectoryAtPath:[self applicationDocumentsDirectory] error:nil];
     for(int i=0;i<[fileArr count];i++)
     {
     NSString *file=[fileArr objectAtIndex:i];
     if(([[[file pathExtension] lowercaseString] isEqualToString:@"png"] || [[[file pathExtension] lowercaseString] isEqualToString:@"jpg"] ||  [[[file pathExtension] lowercaseString] isEqualToString:@"jpeg"]) && ([file hasPrefix:@"iphone_150x150_"] || [file hasPrefix:@"iphone_40x40_"]))
     {
     [fileMgr removeItemAtPath:[[self applicationDocumentsDirectory] stringByAppendingPathComponent:file] error:nil];
     }
     }*/
    //   
    return YES;
}
if ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert| UIUserNotificationTypeBadge) categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
    [self.locationManager startUpdatingLocation];
}

Try this in you appDelegate class 在您的appDelegate类中尝试一下

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //Push notification

    if ([application respondsToSelector:@selector(registerUserNotificationSettings:)])
    {
        UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    else
    {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
    }
    return YES;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何控制Netmera ios sdk何时提示“推送通知”权限? - How to control when Netmera ios sdk will prompt Push notifications permission? iOS推送通知权限提示-用户选择了什么? - iOS push notifications permission prompt - what did the user select? 知道过去是否已显示iOS上的推送通知权限提示 - Knowing if push notifications permission prompt on iOS has been shown in the past iOS 9通知 - 当我请求权限时,为什么我的应用名称丢失了? - iOS 9 Notifications - why is my app name missing when I request permission? 我的生产ios应用没有推送通知 - My production ios app doesn't have push notifications working 自定义推送通知的 iOS 权限对话框 - Customizing the iOS permission dialog for push notifications iOS推送通知:应用程序是提供者? - iOS Push Notifications: App as Provider? 推送通知iOS-提示应用检查资源并在适当时提供本地通知 - Push notifications iOS - prompt app to check resource and provide local notification if appropriate 为什么itunesconnect认为我的应用程序正在注册推送通知? - Why does itunesconnect think my app is registering for push notifications? iOS:推送通知,UIApplicationStateInactive和快速应用切换 - iOS: Push notifications, UIApplicationStateInactive and fast app switching
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM