在 iPhone 上,我们是否可以通过程序设置锁屏、壁纸和铃声?
如果 是 的话,请告诉我如何设置它们呢?
在 iPhone 上,我们是否可以通过程序设置锁屏、壁纸和铃声?
如果 是 的话,请告诉我如何设置它们呢?
这一切都可以轻松完成,但会被苹果拒绝。
通过修改com.apple.SpringBoard.plist
文件中的ringtone
键来改变铃声。
以下代码可用于读取自定义铃声(通过iTunes同步)的实际铃声标题。
NSMutableDictionary *custDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/private/var/mobile/Media/iTunes_Control/iTunes/Ringtones.plist"];
NSMutableDictionary *dictionary = [custDict objectForKey:@"Ringtones"];
NSArray *keys = [dictionary allKeys];
id key = [keys objectAtIndex:indexPath.row];
NSMutableDictionary *customRingtone = [dictionary objectForKey:key];
NSString *name = [customRingtone objectForKey:@"Name"];
cell.textLabel.text = name;
壁纸可以被覆盖在以下位置:
NSString *homePath1 = @"/private/var/mobile/Library/SpringBoard/HomeBackground.jpg";
NSString *homePath2 = @"/private/var/mobile/Library/SpringBoard/HomeBackgroundPortrait.jpg";
NSString *lockPath1 = @"/private/var/mobile/Library/SpringBoard/LockBackground.jpg";
NSString *lockPath2 = @"/private/var/mobile/Library/SpringBoard/LockBackgroundPortrait.jpg";
这些示例是我在Cydia应用程序中使用的。它们并没有太多其他的内容,但应该能够帮助您朝着正确的方向前进。
#import "SBSUIWallpaperPreviewViewController.h"
#import <dlfcn.h>
// open the private framework dynamically
void *handle = dlopen("/System/Library/PrivateFrameworks/SpringBoardUIServices.framework/SpringBoardUIServices", RTLD_NOW);
UIImage *wallpaper = [UIImage imageNamed: @"background.jpg"];
Class sbClass = NSClassFromString(@"SBSUIWallpaperPreviewViewController");
// we create a view controller, but don't display it.
// just use it to load image and set wallpaper
SBSUIWallpaperPreviewViewController *controller = (SBSUIWallpaperPreviewViewController*)[[sbClass alloc] initWithImage: wallpaper];
[controller setWallpaperForLocations: 3]; // 3 -> set both for lock screen and home screen
dlclose(handle);
[SBSUIWallpaperPreviewViewController setWallpaperForLocations:]
:3表示该图像应用于锁定和主屏幕。1表示仅锁定屏幕。2表示仅主屏幕。
PLStaticWallpaperImageViewController
中使用相似的方法,但是它也失败了。看起来iOS认为该应用程序试图更改其沙盒外的某些内容。我还看到PhotoLibrary中还有另一个API,但我需要进行一些反向工程才能弄清楚它所采取的参数。我会在这里及时更新。 - NatePLStaticWallpaperImageViewController
。