Note that there are some explanatory texts on larger screens.

plurals
  1. POpass parameters from push notification to viewDidLoad
    primarykey
    data
    text
    <p>I have an ios app which loads a webpage to show data. I use push notifications for receiving news and I want that depending of which push is received, goes to one page or other (sections inside the same page).</p> <p>In the text received in push notification, I add a word before the text, something like:</p> <pre><code>page1 - text page2 - text2 page3 - text3 ... </code></pre> <p>In android I take the first word and add to the webpage url: www.page.com/ + pageAdded</p> <p>In iOs I think I haveto add this code to didFinishLaunchWithOptions function. But I don't know where I should add the new code for passing the arguments. I add my function so you can tell me where to put it.</p> <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"CityInfoPush" accessGroup:nil]; udid = [keychainItem objectForKey:(__bridge id)kSecValueData]; //if udid is empty , that means we need to generate one and save it on KeyChain if([udid length] == 0){ NSLog(@"No CFUUID found. Creating one..."); //creating CFUUID CFUUIDRef cfuuid = CFUUIDCreate(kCFAllocatorDefault); NSString *cfuuidString = (NSString*)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, cfuuid)); NSLog(@"Device CFUUID created is : %@" , cfuuidString); //saving CFUUID on KeyChain [keychainItem setObject: cfuuidString forKey:(__bridge id)kSecValueData]; //retrieving CFUUID from KeyChain and passing it to udid String. udid = [keychainItem objectForKey:(__bridge id)kSecValueData]; } //For reseting the keyChain (testing) //[keychainItem resetKeychainItem]; NSLog(@"Password Saved in KeyChain is: %@" , udid); self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil]; } else { self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil]; } self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; // Let the device know we want to receive push notifications [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; return YES; } </code></pre> <p>I add the message to the payload for sending it to the apple server like this: </p> <pre><code>// Create the payload body $body['aps'] = array( 'alert' =&gt; $message, 'sound' =&gt; 'default' ); // Encode the payload as JSON $payload = json_encode($body); </code></pre> <p>I am trying to get the alert text (message) in ios like this, but always fails and crash the app:</p> <pre><code>NSString *text=[[lastNotif valueForKeyPath:@"aps"][0] objectForKey:@"alert"]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload