-3

App A is pushing a notification to App B like so:

NSDictionary *data = @{
                           @"alert" : @"Purchase Successful! 1 Remove Ads",
                           @"badge" : @"Increment",
                           @"sounds" : @"Bell.caf",
                           };
    PFPush *push = [[PFPush alloc] init];
    [push setChannels:@[ @"Mets" ]];
    [push setData:data];
    [push sendPushInBackground];

App B Receives the push notification like so:

//
//  ParseStarterProjectAppDelegate.m
//
//  Copyright 2011-present Parse Inc. All rights reserved.
//

#import <Parse/Parse.h>

// If you want to use any of the UI components, uncomment this line
// #import <ParseUI/ParseUI.h>

// If you are using Facebook, uncomment this line
// #import <ParseFacebookUtils/PFFacebookUtils.h>

// If you want to use Crash Reporting - uncomment this line
// #import <ParseCrashReporting/ParseCrashReporting.h>

#import "ParseStarterProjectAppDelegate.h"
#import "ParseStarterProjectViewController.h"

@implementation ParseStarterProjectAppDelegate

#pragma mark -
#pragma mark UIApplicationDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Enable storing and querying data from Local Datastore. Remove this line if you don't want to
// use Local Datastore features or want to use cachePolicy.
[Parse enableLocalDatastore];

// ****************************************************************************
// Uncomment this line if you want to enable Crash Reporting
// [ParseCrashReporting enable];
//
// Uncomment and fill in with your Parse credentials:
 [Parse setApplicationId:@"APPIDHERE" clientKey:@"CLIENTKEYHERE"];
//
// If you are using Facebook, uncomment and add your FacebookAppID to your bundle's plist as
// described here: https://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/
// [PFFacebookUtils initializeFacebook];
// ****************************************************************************

[PFUser enableAutomaticUser];

PFACL *defaultACL = [PFACL ACL];

// If you would like all objects to be private by default, remove this line.
[defaultACL setPublicReadAccess:YES];

[PFACL setDefaultACL:defaultACL withAccessForCurrentUser:YES];

// Override point for customization after application launch.

self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

if (application.applicationState != UIApplicationStateBackground) {
    // Track an app open here if we launch with a push, unless
    // "content_available" was used to trigger a background push (introduced in iOS 7).
    // In that case, we skip tracking here to avoid double counting the app-open.
    BOOL preBackgroundPush = ![application respondsToSelector:@selector(backgroundRefreshStatus)];
    BOOL oldPushHandlerOnly = ![self respondsToSelector:@selector(application:didReceiveRemoteNotification:fetchCompletionHandler:)];
    BOOL noPushPayload = ![launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    if (preBackgroundPush || oldPushHandlerOnly || noPushPayload) {
        [PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
    }
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                    UIUserNotificationTypeBadge |
                                                    UIUserNotificationTypeSound);
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
                                                                             categories:nil];
    [application registerUserNotificationSettings:settings];
    [application registerForRemoteNotifications];
} else
#endif
{
    [application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                     UIRemoteNotificationTypeAlert |
                                                     UIRemoteNotificationTypeSound)];
}

return YES;
}

#pragma mark Push Notifications

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation saveInBackground];

[PFPush subscribeToChannelInBackground:@"Mets" block:^(BOOL succeeded, NSError *error) {
    if (succeeded) {
        NSLog(@"ParseStarterProject successfully subscribed to push notifications on the broadcast channel.");
    } else {
        NSLog(@"ParseStarterProject failed to subscribe to push notifications on the broadcast channel.");
    }
}];
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
if (error.code == 3010) {
    NSLog(@"Push notifications are not supported in the iOS Simulator.");
} else {
    // show some alert or otherwise handle the failure to register.
    NSLog(@"application:didFailToRegisterForRemoteNotificationsWithError: %@", error);
}
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];

if (application.applicationState == UIApplicationStateInactive) {
    [PFAnalytics trackAppOpenedWithRemoteNotificationPayload:userInfo];
}
}

///////////////////////////////////////////////////////////
// Uncomment this method if you want to use Push Notifications with Background App Refresh
///////////////////////////////////////////////////////////
//- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
//    if (application.applicationState == UIApplicationStateInactive) {
//        [PFAnalytics trackAppOpenedWithRemoteNotificationPayload:userInfo];
//    }
//}

#pragma mark Facebook SDK Integration

///////////////////////////////////////////////////////////
// Uncomment this method if you are using Facebook
///////////////////////////////////////////////////////////
//- (BOOL)application:(UIApplication *)application
//            openURL:(NSURL *)url
//  sourceApplication:(NSString *)sourceApplication
//         annotation:(id)annotation {
//    return [PFFacebookUtils handleOpenURL:url];
//}

@end

How come I don't hear any sounds go off when App B receive's the push notification? No sound is played when the app is closed and the banner notification appears (which I'd like a sound), no sound is played when the app is open and the notification appears (just a vibrate, that's odd). Why is that and how do I fix it?

Wyetro
  • 8,439
  • 9
  • 46
  • 64
Creagen
  • 478
  • 5
  • 17
  • possible duplicate of [No Sound in ios 8 Parse push](http://stackoverflow.com/questions/26488243/no-sound-in-ios-8-parse-push) – soulshined Aug 28 '15 at 01:22

1 Answers1

1

Do it like this:

 NSDictionary *data = @{
                           @"alert" : @"you daily milk temp",
                           @"badge" : @"Increment",
                           @"sound" : @"super.caf"
                           };
    PFPush *pusher = [[PFPush alloc] init];
    [pusher setChannels:@[ @"deviceTemperatureReading" ]];
    [pusher setData:data];
    [pusher sendPushInBackground];

"super.caf" is a sound file

Wyetro
  • 8,439
  • 9
  • 46
  • 64
Larry Pickles
  • 4,615
  • 2
  • 19
  • 36
  • do i just add super.caf to App B and when App A sends that push, App B should play that sound? – Creagen Aug 28 '15 at 01:30
  • if both users have this in the app bundle then this means that whoever gets the push then hears sound. Also, you should be marking your questions as having been answered or no, by the way – Larry Pickles Aug 28 '15 at 01:31
  • Both apps have the audio file and still no sound is going off. Do both apps have to have AVFoundation? – Creagen Aug 28 '15 at 01:34
  • k, well this works for me, I dont have your code, I dont know what you are doing, so perhaps someione else can show you the same code and then it will work? – Larry Pickles Aug 28 '15 at 01:38
  • no more answers from me, I'm done answering your questaions, thanks – Larry Pickles Aug 28 '15 at 01:38