0
A
回答
0
你不能直接從應用程序那樣做。如果你想這樣做,你需要讓UISwitch將信息發送到後端,將這些信息存儲在數據庫中,並停止向該用戶發送推送通知。
0
應用程序首次啓動時會爲推送通知(APN)註冊。一旦交換機啓動後,您就無法使用交換機初始化APN。但是,您可以編寫您的應用程序,以便在收到APN後,交換機可以選擇在用戶界面上執行「某些事情」。
例如,你可以有這樣的代碼:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
NSString *alert = [apsInfo objectForKey:@"alert"];
// do what you need with the data...
[[NSNotificationCenter defaultCenter] postNotificationName:@"ReceivedNotificationAlert" object:self];
}
您可以使用UISwitch要麼做一些事情,或者不與NSNotification「ReceivedNotificationAlert」。例如:
if(switchAPNprocess.on){
// process APN
}
else {
// ignore APN
}
1
You can also do it in the following way.
create a IBOutlet for UISwitch
@property (strong, nonatomic) IBOutlet *pushNotificationSwitch;
and in Action method, store the value in NSUserDefaults.
- (IBAction)pushNotificationSwitchChanged:(id)sender
{
NSNumber *switch_value = [NSNumber numberWithBool:[self.pushNotificationSwitch isOn]];
[[NSUserDefaults standardUserDefaults] setObject:switch_value forKey:RECIEVE_APNS];
[[NSUserDefaults standardUserDefaults] synchronize];
}
and check it in viewdidload.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSNumber *sett = [[NSUserDefaults standardUserDefaults] valueForKey:RECIEVE_APNS];
if([sett boolValue])
{
[self.pushNotificationSwitch setOn:YES];
}
else{
[self.pushNotificationSwitch setOn:NO];
}
}
and In AppDelegate.m, add the following code
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSNumber *sett = [[NSUserDefaults standardUserDefaults] objectForKey:RECIEVE_APNS];
if([sett boolValue])
{
int currentBadgeCount = [[NSUserDefaults standardUserDefaults] integerForKey:@"BadgeCount"];
//Set the baadge count on the app icon in the home screen
int badgeValue = [[[userInfo valueForKey:@"aps"] valueForKey:@"badge"] intValue];
[UIApplication sharedApplication].applicationIconBadgeNumber = badgeValue + currentBadgeCount;
[[NSUserDefaults standardUserDefaults] setInteger:badgeValue + currentBadgeCount forKey:@"BadgeCount"];
NSString *alertString = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];
NSString *playSoundOnAlert = [NSString stringWithFormat:@"%@", [[userInfo objectForKey:@"aps"] objectForKey:@"sound"]];
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath],playSoundOnAlert]];
NSError *error;
if (alertString.length > 0)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"App Name" message:alertString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = 1;
[audioPlayer play];
[alert show];
}
}
}
enter code here
相關問題
- 1. 推送通知通過GCM
- 2. 通過PHP推送通知?
- 3. 通過quickblox推送通知
- 4. 通過Wifi推送通知
- 5. 通過WiFi推送通知
- 6. 通過Firebase發送推送通知
- 7. 通過node.js發送android推送通知
- 8. 通過Android推送通知啓動應用程序
- 9. 通過推送通知啓動調試應用程序
- 10. Telerik推送通知過濾
- 11. 過濾Apple推送通知
- 12. 啓用聲音的JavaPNS推送通知
- 13. 強制啓用推送通知iOS
- 14. 無法啓用推送通知
- 15. 本地推送通知啓用聲音
- 16. 推送通知
- 17. 推送通知
- 18. 推送通知
- 19. 推送通知
- 20. 推送通知
- 21. 推送通知
- 22. 推送通知
- 23. 推送推送通知
- 24. startUpdating LocationManager通過靜默推送通知
- 25. Android:通過C2DM推送通知
- 26. 通過推送通知打開spicific ViewController
- 27. 通過PHP廣播推送通知
- 28. 通過webview的網站推送通知?
- 29. 醒來通過推送通知
- 30. Apple通過代理推送PHP通知
不......那不是我的意思。我希望交換機初始化推送通知。我激活交換機,然後在應用程序註冊推送通知時獲取庫存UIAlertView – 2013-05-07 20:23:27