我是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;
}
答案 0 :(得分:2)
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];
}
答案 1 :(得分:0)
在 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;
}