我试图通过parse.com文档中概述的应用程序委托来显示包含在推送通知中的消息。显示来自应用程序委托的警报,然后显示来自viewDidload的警报
我遇到的问题是,在我的viewdidload方法为我的第一个视图控制器,我提出了一个警告,用户必须在使用应用程序之前看到。
如何在用户从viewdidload方法看到警报后从我的应用程序委托调用方法?
编辑:
所以我有,如在评论中建议,增加了一个全局变量,我设置为true,一旦我已经从我的viewDidLoad方法显示的警报,但是从我的appDelegate仍然通知警报没有出现。
这里是我的应用程序delegate.m文件:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[Parse setApplicationId:@"xxxxxxxxxxxxxxxx"
clientKey:@"xxxxxxxxxxxx"];
// Register for Push Notitications, if running iOS 8
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
} else {
// Register for Push Notifications before iOS 8
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound)];
}
return YES;
NSDictionary *notificationPayload = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
if (Notification == true) {
if (![pushText isEqual: @""]) {
pushText = [[notificationPayload objectForKey:@"aps"] objectForKey:@"alert"];
UIAlertView *alert_news = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"News", "")
message:pushText
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles: nil];
[alert_news show];
}
}
}
,这里是我的viewDidLoad方法:
RoadSafetyAppAppDelegate *AppDelegate;
- (void)viewDidLoad
{
AppDelegate = (RoadSafetyAppAppDelegate *)[[UIApplication sharedApplication] delegate];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
backgroundImage.alpha = 0.3;
toRecipients = [[NSArray alloc]initWithObjects:@"[email protected]", nil];
static int appCounter;
if (appCounter < 1 ) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Disclaimer", "")
message:NSLocalizedString(@"Using a mobile phone whilst driving is against the law. Ensure that you are not behind the wheel when using this app.", "")
delegate:nil
cancelButtonTitle:@"I agree to not use a mobile phone while driving"
otherButtonTitles: nil];
[alert show];
appCounter = appCounter+1;
AppDelegate.NotificationAlert = @"1";
AppDelegate.Notification = true;
}
}
从应用程序委托中,您可以在视图控制器中设置showPushMessage bool变量,然后在showPushMessage == YES的情况下解除第一个警报后显示推送消息警报。 – 2014-12-02 01:20:02
你能提供一些代码来概述一下吗?我有点新使用应用程序委托本身进行其他操作 – scb998 2014-12-02 01:21:36
如果应用程序已经打开并且用户已经接受了免责声明警告,应用程序应立即显示推送通知警报,对不对? – 2014-12-08 12:10:12